安装
npm i element-ui -S
1.完整引入
在main.js中写入以下内容,这样就可以直接使用elementUI的任意组件了
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
2.按需引入
安装
npm install babel-plugin-component -D
修改babel.config.js文件
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
["@babel/preset-env", { "modules": false }]
],
plugins: [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
你希望引入部分组件 button和Select,那么需要在main.js中输入以下内容
// 按需引用
import { Button,Select,Option} from 'element-ui';
Vue.component('el-button',Button)
Vue.component("el-select",Select)
Vue.component("el-option",Option)