makeStyles:意外令牌,应为“,”

时间:2018-12-14 10:02:12

标签: reactjs material-ui

看文档(https://material-ui.com/css-in-js/basics/),这应该是可能的:

const useStyles = makeStyles({
    h2: {
        font-family: '-apple-system, BlinkMacSystemFont,"Segoe UI", Roboto, Helvetica, Arial, sans-serif'
    }
});

但是在尝试运行时,我得到了:

  Line 119:  Parsing error: Unexpected token, expected ","

  117 | const useStyles = makeStyles({
  118 |     h2: {
> 119 |         font-family: '-apple-system, BlinkMacSystemFont,"Segoe UI", Roboto, Helvetica, Arial, sans-serif'                                                                     
      |             ^
  120 |     }
  121 | });
  122 | 

我不确定自己哪里出了问题吗?

2 个答案:

答案 0 :(得分:3)

必须用短划线引起引用。试试这个:

const useStyles = makeStyles({
    h2: {
        'font-family': '-apple-system, BlinkMacSystemFont,"Segoe UI", Roboto, Helvetica, Arial, sans-serif'                                                                     
    }
});

答案 1 :(得分:1)

font-family不是有效的标识符,您必须将其用引号引起来:

'font-family': ...