[英]Vuex state not updating after mutation
我正在尝试使用Vue / Vuex应用程序中的突变将一些值设置为状态。
component.vue
created() {
let clubId = {'clubId': 31};
this.$store.dispatch(
"clubConfiguration/getClub",
clubId
);
}
action.js
getClub(context, payload) {
ApiService().post('/club/getSingleClub', {
"ClubId": payload.clubId
})
.then(res => {
context.commit('GET_CLUB_INFORMATION', res.data.data[0]);
})
.catch(err => {
console.log(err)
})
}
mutation.js
GET_CLUB_INFORMATION(state, payload) {
state.Name = payload.Name
console.log(state);
}
state.js
Name: '',
mapLocation: { lat: 39.585693, lng: 2.622868, zoom: 18 },
courts: [
{
id: 0,
number: 1,
name: 'Court 1',
map: null
}
]
现在,在console.log中,我在变异中显示有效负载中的“名称”已附加到状态以及其他状态属性。 但是当我检查Vue开发人员工具或尝试从组件中访问state.Name
时,它将状态state中的state.Name
属性显示为undefined
。 我做错了什么?
找到了! 你的突变应该是
GET_CLUB_INFORMATION(state, payload) {
state.Name = payload
console.log(state);
}
因为您只传递名称,而不传递整个有效负载
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.