Vue.js 3 类型“CreateComponentPublicInstance”上不存在属性“$store”

Bil*_*hia 6 typescript vue.js vuex

我在我的项目中使用 vue.js 3、typescript 和 vuex 4。this.$store但是在我的.vue文件上使用时出现此错误

Property '$store' does not exist on type 'CreateComponentPublicInstance<{}, {}, { exchanges: Exchange[]; isValidNodeUrl: boolean; isValidSelectedNetworks: boolean; web3: "" | Web3; privateKey: string; jsonKeystore: string; jsonKeystorePassword: string; ... 24 more ...; botIsRunning: boolean; }, ... 14 more ..., {}>'
Run Code Online (Sandbox Code Playgroud)

vuex.d.ts我根据此文档 添加了内容,但仍然遇到相同的错误https://next.vuex.vuejs.org/guide/typescript-support.html

import { Store } from "vuex";
import { ComponentCustomProperties } from "vue";

import { State } from "@/interfaces/bot";

declare module "@vue/runtime-core" {
  // Declare your own store states.

  interface ComponentCustomProperties {
    $store: Store<State>;
  }
}

Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

小智 -1

检查 tsconfig.json。可能出现无法识别文件的错误。请尝试通过再次删除来重新添加文件。