vue-cli按需引入Element UI組件


一、環境

  使用vue-cli搭建的環境

二、安裝 babel-plugin-component

  npm install babel-plugin-component -D

三、修改.babelrc文件,可以直接拷貝一下的配置,紅色部分是在原來基礎上添加的。

 1 {
 2   "presets": [
 3     ["env", {
 4       "modules": false,
 5       "targets": {
 6         "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
 7       }
 8     }],
 9     "stage-2"
10   ],
11   "plugins": [
12     "transform-vue-jsx",
13     "transform-runtime",
14     [
15       "component",
16       {
17         "libraryName": "element-ui",
18         "styleLibraryName": "theme-chalk"
19       }
20     ]
21   ],
22   "env": {
23     "test": {
24       "presets": ["env", "stage-2"],
25       "plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
26     }
27   }
28 }

四、在main.js文件添加所需的組件即可,例如添加Button組件;詳情請看Element UI 官網

import { Button} from 'element-ui'

Vue.use(Button)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM