美文网首页
vue+ts,引入element-ui和vant,导致$noti

vue+ts,引入element-ui和vant,导致$noti

作者: 没有昵_称 | 来源:发表于2020-09-23 17:03 被阅读0次

    报错原因:
    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"],
     }
    
    

    相关文章

      网友评论

          本文标题:vue+ts,引入element-ui和vant,导致$noti

          本文链接:https://www.haomeiwen.com/subject/qkyoyktx.html