Element按需引入

2023-11-09

ElementUI网址:https://element.eleme.cn/#/zh-CN/component/quickstart
1.1.安装 babel-plugin-component:npm install babel-plugin-component -D
2.将babel.config.js修改为:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
		["@babel/preset-env", { "modules": false }],
  ],
	plugins:[
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

3.如果你只希望引入部分组件,比如 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.component('atguigu-button', Button);
//Vue.component('atguigu-row', Row);
//Vue.component('atguigu-date-picker', DatePicker);

new Vue({
  el: '#app',
  render: h => h(App)
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Element按需引入 的相关文章