使用 Vue-Cli 腳手架創建 Vue 項目實現 Element 的按需引入
-
安裝
element-ui和babel-plugin-component和babel-preset-es2015依賴npm intall element-ui --savenpm install babel-plugin-component -Dnpm install babel-preset-es2015 -D
-
修改
.babelrc文件-
{ "presets": [["es2015", { "modules": false }]], "plugins": [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] }
-
-
在
main.js文件下,按需引入組件,且掛在到Vue實例上-
import { Butto(組件名) } from 'element-ui' Vue.use(Button)
-
-
在
template中便可使用Button組件-
<template> <div> <el-button type='primary'>按鈕</el-button> </div> </template>
-
