vue3+ts中使用this.$store
报错Property '$store' does not exist on type
解决办法
在src目录下添加一个名为:shims-vuex.d.ts
的文件,添加以下内容即可
/* eslint-disable */
import { Store } from '@/store' // path to store file
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$store: Store;
}
}
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'App',
computed: {
todoList(): [] {
return this.$store.state.list
},
},
})
</script>