问题
my store/index.js is :
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default
new Vuex.Store({
state: {
name: 'Alicia Vikander',
age: 20,
dob: '20/08/1990'
},
mutations: {
updateName(state, name) => {
state.name = name
}
}
})
and my component.vue is :
<template>
<div>
{{ $store.state.name }}
</div>
</template>
why i am getting error of
cannot read property 'state' of undefined
in vue js ? please help.. thanks in advance
回答1:
Are you sure you have injected store to the component like this:
let store = new Vuex.Store({
state: {
name: 'Alicia Vikander',
age: 20,
dob: '20/08/1990'
},
mutations: {
updateName(state, name) => {
state.name = name
}
}
})
new Vue({
store,
el: '#app',
render: h => h(App)
});
来源:https://stackoverflow.com/questions/52055428/why-i-am-getting-error-of-cannot-read-property-state-of-undefined-in-vue-js