微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue project - ElementUI按需引入

安装按需引入包

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:

把将要使用到的组件写到一个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] 举报,一经查实,本站将立刻删除。

相关推荐