3
我正在创建counter using Vue & Vuex 2。
当试图访问商店对象的count属性时,使用this.$store.state.count
,我得到一个Cannot read property 'state' of undefined
错误。
错误不会显示出来,当我在main.js
内创建存储实例而不是导入它时,一切正常。
main.js
import Vue from 'vue'
import Vuex from 'Vuex'
import App from './App.vue'
import store from './store'
new Vue({
el: '#app',
store,
render: h => h(App)
})
store.js
import Vue from 'Vue'
import Vuex from 'Vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
count: 1
}
});
Counter.vue
export default {
name: 'counter',
template: `<span>{{ count }}</span>`,
computed: {
count() {
return this.$store.state.count
}
},
}
任何想法有什么不对的智慧h商店导入?
在切换Vue项目的打包程序时,我自己遇到了类似的问题,那就是该商店的文件正在导入Vue的'vue/dist/vue'模块 –