1、npm安裝【全局安裝element】? ?
npm i element-ui -S
2、按需引入,借助??babel-plugin-component,
????????2.1、首先安裝?babel-plugin-component,
npm install babel-plugin-component -D
????????2.2、將.babelrc修改為:【是項目中的babel.config.js文件】
{
"presets": [["es2015", { "modules": false }]],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
? ? ? ? 2.3、在main.js中引入需要的組件
比如:Button,Select
//引入需要的組件
import { Button, Select } from 'element-ui';
//使用組件
Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
????????2.4、或者掛載在原型上使用文章來源:http://www.zghlxwxcb.cn/news/detail-599370.html
//引入組件
import {MessageBox } from 'element-ui';
//掛載到原型上使用
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
注意:如果依賴下載不了,在每行命令后面加上??文章來源地址http://www.zghlxwxcb.cn/news/detail-599370.html
--legacy-peer-deps
到了這里,關(guān)于element UI 按需引入的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!