背景
今天,在学习vue.js中,我引入了element-ui。执行步骤如下:
a> vue init webpack-simple element-ui
b> cd my-pro(打开生成的vue项目)
c> cnpm install(此处用的是国内淘宝镜像)
d> 我先用的是webpack-simple 所以要先配置一下style-loader:cnpm install style-loader -S
e> 配置安装element-ui:cnpm install element-ui -S
f> 安装完成后用编辑器打开项目,在main.js添加以下内容
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI) //记得全局注册
g> 运行了npm run dev
结果
- 1.在引入element-ui时,运行npm run dev,突然,提示如下错误:
ERROR in ./node_modules/_element-ui@2.13.0@element-ui/lib/theme-chalk/fonts/elem ent-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)
- 2.通过一番google,发现原来我安装了element-ui,但是在webpack.config.js中没有解析引入的路径。解决方法其实很简单,就是在webpack.config.js中引入css解析路径即可。
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
},
//引入element-ui的css解析路径
{
test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
loader: 'file-loader'
}