Vant與Element-ui出現Property '$notify' must be of type 'ElNotification'錯誤

原因是兩個組件庫都在應用上添加了 $notify 方法;

解決方法是: 只安裝一個組件庫, 另一個組件庫按需引入

報錯示例:

npm install vant element-ui
# vant 和 element-ui 都有 $notify 方法, 會報錯
import Vue from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(Vant);
Vue.use(ElementUI);

解決方案:

import Vue from 'vue';
import Vant from 'vant';
import 'vant/lib/index.css';

// 按需引入你用到的組件, 而不是安裝整個組件庫
import ElButton from 'element-ui/lib/button';
import 'element-ui/lib/theme-chalk/button.css';

Vue.use(Vant);
Vue.component('el-button', ElButton);

tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      // 指向正確的聲明映射
      "element-ui/lib/button": ["node_modules/element-ui/types/button"]
    }
  }
}

 

官方issue:

https://github.com/youzan/vant/issues/3324

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章