【问题标题】:Vue.js 3 Property '$store' does not exist on type 'CreateComponentPublicInstanceVue.js 3 属性“$store”在“CreateComponentPublicInstance”类型上不存在
【发布时间】:2021-08-26 05:55:56
【问题描述】:

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

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 ..., {}>'

我已根据此文档添加了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>;
  }
}

有人可以帮我吗?

【问题讨论】:

  • 它应该命名为shims-vuex.d.ts,正如我在这里所说的stackoverflow.com/questions/64412243/…
  • @BoussadjraBrahim 重命名后仍然是同样的错误..
  • 尝试重启编译器和编辑器
  • @BoussadjraBrahim 是的,已经做过几次了..
  • 确保 'src' 文件夹中的 'vuex.d.ts'

标签: typescript vue.js vuex


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2021-02-01
  • 2021-09-08
  • 1970-01-01
  • 2018-04-25
  • 2021-11-07
  • 1970-01-01
  • 2023-02-02
  • 2021-12-19
  • 2018-11-17
相关资源
最近更新 更多