vue+ts,引入element-ui和vant,导致$notify的类型冲突

报错原因:
vantelement-ui都有$notify 方法

解决方法:
第一步只安装一个组件库,另外一个按需加载

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI);
// 按需引入你需要的组件 以Switch为例

import Switch from 'vant/lib/switch'
Vue.component('van-switch', Switch);

第二步因为vanttypes里没有独立的比如switch.d.ts的文件,所以在项目中创建switch.d.ts文件,这个文件的路径components/vant/switch.d.ts

//switch.d.ts
import { VanComponent } from 'vant/types/component'
export class Switch extends VanComponent {}

第三步,修改tsconfig.json文件

compilerOptions:{
  ...
 paths:{
    ...
    // 指向正确的声明映射
   "vant/lib/switch": ["src/components/vant/switch"],
 }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。