Element-ui按需导入说明1.新建一个vue项目npmi-g@vue/clivuecreatemy-appcdmy-app2。安装element-uiyarn添加element-uiyarn添加babel-plugin-component-D3。修改babel.config。如果js没有这个文件,就新建一个module.exports={presets:["@vue/cli-plugin-babel/preset"],plugins:[["component",{libraryName:"element-ui",styleLibraryName:"theme-chalk",},],],};4.修改main.jsimportVuefrom'vue'importElementUIfrom'element-ui'//所有的样式文件还是需要导入,目前还没找到好的导入方式'element-ui/lib/theme-chalk/index.css'importlangfrom'element-ui/lib/locale/lang/zh-CN'importlocalefrom'element-ui/lib/locale'importAppfrom'./App.vue'importrouterfrom'./router'importstorefrom'./store'Vue.config.productionTip=false//element-uiconfigObject.entries(ElementUI).forEach(([key,component])=>{if(/^[A-Z]+/.test(key)){switch(key){case'Loading':Vue.use(component.directive)Vue.prototype.$loading=component.service中断case'Notification':Vue.prototype.$notify=componentbreakcase'Message':Vue.prototype.$message=componentbreakcase'MessageBox':Vue.prototype.$msgbox=componentVue.prototype.$alert=component.alertVue.prototype.$confirm=component.confirmVue.prototype.$prompt=component.promptbreakdefault:Vue.use(component)}}})Vue.prototype.$ELEMENT={size:'small',zIndex:3000}locale.use(lang)newVue({路由器,商店,渲染:h=>h(App)}).$mount('#app')
