我有来自cli的最新Vue项目。只是在玩Vuex和商店。
默认项目具有此初始化。
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import './registerServiceWorker';
Vue.config.productionTip = false;
new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app');
商店看起来像这样:
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
stateName: 'STORE-NAME',
},
mutations: {
},
actions: {
},
});
我的证监会是这样的:
<template>
<div class="about">
<h1>This is the Probate page</h1>
<p>State Name: {{ localName }}</p>
</div>
</template>
<script lang="ts">
export default {
data(){
return {
localName: 'COMPONENT-NAME',
};
},
created(){
this.localName = this.$store.state.stateName;
},
};
</script>
运行'npm run serve'时出现的错误是
ERROR in /Users/*/Documents/projects/legalcove-single-page-app/src/views/Probate.vue
27:14 Property 'localName' does not exist on type '{ data(): { localName: string; }; created(): void; }'.
26 |
> 27 | this.localName = this.$store.state.stateName;
| ^
28 |
29 | },
30 | };
Version: typescript ERROR in /Users/*/Documents/projects/lc-single-page-app/src/views/Probate.vue3.1.1
, tslint 5.11.027:31
Property '$store' does not exist on type '{ data(): { localName: string; }; created(): void; }'.
Time: 3011 ms
26 |
> 27 | this.localName = this.$store.state.stateName;
| ^
28 |
29 | },
但是在运行该应用程序时,我在浏览器中没有出现任何错误,并且可以正常运行。我的屏幕上显示了stateName
的值。