首页 > 其他分享 >Vue2按需引入elementUI组件

Vue2按需引入elementUI组件

时间:2022-08-23 00:47:08浏览次数:84  
标签:Vue elementUI babel Button component Vue2 组件 import

按需引入
官方文档介绍

借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。

首先
安装 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.use(Button)
Vue.use(Select)

new Vue({
  el: '#app',
  render: h => h(App)
});

标签:Vue,elementUI,babel,Button,component,Vue2,组件,import
From: https://www.cnblogs.com/echohye/p/16614747.html

相关文章