报错

类型“{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<{} & {} & {}> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 10 more ...; $watch(source: string | Function, cb: Function, options?: WatchOptions<...> | undefined): WatchStopHandle; } & ... 4 more ... & ComponentC...”上不存在属性“xxxxx”。

找到文件shims-vue.d.ts 或者新建一个`.ts`或".d.ts"文件

添加以下代码:

export {}

declare module 'vue' {
  interface ComponentCustomProperties {
    $filters: any
  }
}

注意:一定要添加export {} 不然会覆盖掉原来的

参考vue3官方文档:TypeScript 与选项式 API | Vue.js

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐