我的store / index.js是:
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
}
}
})
我的component.vue是:
<template>
<div>
{{ $store.state.name }}
</div>
</template>
为什么在vue js中出现“无法读取未定义的属性'state'的错误”的错误?请帮助..在此先感谢
答案 0 :(得分:0)
您确定已将存储注入到这样的组件中:
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)
});