ts+vuex,类型“CreateComponentPublicInstance上不存在属性“$store”
最近写vite,封装vuex出现this找不到$store问题。
原因是由于vuex没有像vue-router一样封装$。
解决办法
方法一、给this定义类型
(this as any).$store.state.xxx
方法二、声明一个$store
import { ComponentCustomProperties } from 'vue'
import { Store } from 'vuex'declare module '@vue/runtime-core' {// declare your own store statesinterface State {}// provide typings for `this.$store`interface ComponentCustomProperties {$store: Store}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
