Uni-App解决全局变量和wx变量在TS中类型报错

2024-05-12  本文已影响0人  FateOfKing

问题1:Cannot find name 'wx'.Vetur(2304)

微信小程序 API 的 TypeScript 类型定义文件

安装

通过独立 npm 包

npm install miniprogram-api-typings

安装后手动导入:

或者在 ts 配置中指定:

或者通过 三斜杠指令 引用:

或:

通过 DefinitelyTyped

npm install @types/wechat-miniprogram

问题2:Property '$xxx' does not exist on type 'CombinedVueInstance<Vue, {}, { dotImage(): any; }, unknown, Readonly<{ title: string; type: string; }>>'.

问题出现症状


image.png

解决办法:在shims-uni.d.ts中添加

declare module 'vue/types/vue' {
  interface Vue {
    $xxx: string
  }
}

上一篇 下一篇

猜你喜欢

热点阅读