vue 项目中引入 Element-UI 之后 报错解决方法
刚开始引入 Element-UI 的时候 , 运行 npm run dev 报以下错误:
ERROR in ./node_modules/element-ui/lib/theme-chalk/fonts/element-icons.ttf
Module parse failed: Unexpected character '' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
@ ./node_modules/css-loader!./node_modules/element-ui/lib/theme-chalk/index.css 7:894-930
@ ./node_modules/element-ui/lib/theme-chalk/index.css
@ ./src/main.js
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js
原因:
是因为 webpack 没有配置处理 elementUI 的样式文件
解决方法
- 在 webpack.config.js 文件中添加以下内容(module 中)
rules: [
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader'
},
我的这样解决了报错问题。
本文介绍在Vue项目中引入Element-UI后遇到的字体图标加载失败问题及解决方案。错误源于Webpack未正确配置处理Element-UI的样式文件,通过在webpack.config.js中添加特定的loader规则,成功解决报错。
3051

被折叠的 条评论
为什么被折叠?



