700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Property ‘$store‘ does not exist on type ‘CreateComponentPublicInstance的解决办法

Property ‘$store‘ does not exist on type ‘CreateComponentPublicInstance的解决办法

时间:2020-10-07 23:18:11

相关推荐

Property ‘$store‘ does not exist on type ‘CreateComponentPublicInstance的解决办法

Property ‘$store’ does not exist on type 'CreateComponentPublicInstance的解决办法

项目:vue3 + Typescript + Vuex

问题原因:Vuex不提供开箱即用的this.$store属性类型。与TypeScript一起使用时,必须声明自己的模块扩充。

解决办法:在src文件夹下新建文件夹vue.d.ts,内容为:

// vuex.d.tsimport {ComponentCustomProperties } from '@/vue'import {Store } from 'vuex'declare module '@vue/runtime-core' {// declare your own store statesinterface State {orbital}// provide typings for `this.$store`interface ComponentCustomProperties {$store: Store<State>}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。