第一步:npm 安装
npm i element-ui -S
第二步:借助 babel-plugin-component
npm install babel-plugin-component -D
然后在文件夹找到 babel.config.js
复制下面代码进去
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
如图
第三步重启项目
接下来,如果你只希望引入部分组件,比如 Button 和 Select,
那么需要在 main.js 中写入以下内容:
这一步相当于注册全局组件
import Vue from 'vue';
import { Button, Select } from 'element-ui';
import App from './App.vue';
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或写为
* Vue.use(Button)
* Vue.use(Select)
*/
new Vue({
el: '#app',
render: h => h(App)
});
剩下的去组件那里引入就行了