【发布时间】: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