-
Notifications
You must be signed in to change notification settings - Fork 54
Not planned
Description
同样的方式在 Vue 框架中没事,效果非常理想,但在 React 中当我试图 import "./iconfont/iconfont.js"
JS 文件的时候,出现以下错误:
Failed to compile
./src/iconfont/iconfont.js
Line 1:1: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:256489: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:256503: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:256562: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:256972: Expected an assignment or function call and instead saw an expression no-unused-expressions
Line 1:257259: Expected an assignment or function call and instead saw an expression no-unused-expressions
Search for the keywords to learn more about each error.
使用的是最新的 create-react-app 16.13 版本建的项目:
Activity
condorheroblog commentedon Jun 10, 2020
看官网的回答率,估计不可能被翻牌子了,还是自问自答吧😂
在 React 的组件中无法使用,但是在 html 文件是可以使用的,那我们就从项目的 index.html 下手,只需要在这个文件里面按教程配置下就OK了。
具体点就是把在 阿里妈妈 (iconfont)下载的文件包,放在项目 index.html 文件所在目录,即 public 文件夹下。然后按教程根据你的情商配置:
注意⚠️ 在 React 组件中使用的时候,
xlink:href
替换成xlinkHref
:看到的,不用谢。😄
tthallos commentedon Jul 9, 2020
加个
就可以了
yang-builds commentedon Apr 12, 2021
哎 这就比较麻烦咯