VUE項目中同時引入Antd 和ElementUI 組件重名樣式異常解決方案


公司Vue項目中根據需求同時引入了Antd 和 ElementUI 導致部分地方組件使用Antd的$confirm 和$message組件時,由於elementUI中也存在同名的組件,導致頁面樣式異常。

 

解決方案1:給antd的組件改名

Vue.use(Antd)
Vue.prototype.$antdconfirm = Vue.prototype.$confirm

使用的時候:
this.$antdconfirm({....

解決方案2:按需引用

將你需要使用elementUi 的組件提前抽取到一個單獨js文件中去

這里是抽取的elementUI的ColorPicker組件

import{
ColorPicker
} from 'element-ui'
const element = {
install:function (Vue) {
Vue.use(ColorPicker)
}
}
export default elementColorPicker

在main.js中引入

import elementui from './utils/elementColorPicker'
Vue.use(elementui)

使用confirm的時候正常使用即可
this.$confirm({....


 

 

 
        





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM