安装按需引入包
npm install babel-plugin-component
babel.config.js:
按需引入配置
module.exports = { presets: [ '@vue/cli-plugin-babel/preset', //1.ElementUI 按需引入配置 ["@babel/preset-env", { "modules": false }] ], //2.ElementUI 按需引入配置 "plugins": [ [ "component", { "libraryName": "element-ui", "styleLibraryName": "theme-chalk" } ] ] }
src/element/index.js:
// 导入自己需要的组件 import {Select,Option,OptionGroup,Input,Tree,Dialog,Row,Col,Button} from 'element-ui' const element = { install: function (Vue) { Vue.use(Select) Vue.use(Option) Vue.use(OptionGroup) Vue.use(Input) Vue.use(Tree) Vue.use(Dialog) Vue.use(Row) Vue.use(Col) Vue.use(Button) } } export default element
scr/main.js:
注册使用element组件(src/element/index.js)
import Vue from 'vue' import App from './App.vue' //导入将要使用的组件 import element from './element/index' //注册将要使用的组件 Vue.use(element) Vue.config.productionTip = false new Vue({ render: h => h(App), }).$mount('#app')
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。