在Vue2引入 Element-UI
1.安装
npm i element-ui -S
2.按需引入(借助 babel-plugin-component,只引入需要的组件,以达到减小项目体积的目的。)
首先,安装 babel-plugin-component
npm install babel-plugin-component -D
3.修改.babelrc(修改plugins里的内容)
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
}
],
"stage-2"
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
4.在页面中写入并在mian.js中引入需要的组件并注入。
import { Button, Select } from 'element-ui';
Vue.use(Button)
Vue.use(Select)
5.显示