我有以下vuex配置
import listing from '@/store/modules/listing'
var store = new Vuex.Store({
modules:
{
listing: listing,
},
和列出模块代码看起来像
import Vue from 'vue'
const listing = {
namespaced: true,
state: {
listingAllItems: [],
listingSelectedItems: [],
},
mutations: {
updateListingAllItems(state, param) {
},
},
actions: {
getListingItems(context, param) {
var tempThis = this;
return new Promise((resolve, reject) => {
var url = 'http://WS/';
Vue.http.get(url).then(response => {
tempThis.commit('updateListingAllItems', response.data);
}).catch(error => reject(error));
})
},
},
getters: {}
}
export default listing
在致电 this.commit('updateListingAllItems', response.data) 时我正在 [vuex] unknown mutation type: updateListingAllItems .
Namespaced getter和actions将接收本地化的getter,dispatch和commit . 换句话说,您可以使用模块资产而无需在同一模块中写入前缀
为什么我收到错误消息呢?
1 回答
在一个动作方法
this
里面是商店 . 您的代码在商店实例上提交了一个非前缀的变异 .如果你改变了
tempThis.commit('updateListingAllItems', response.data);
至
context.commit('updateListingAllItems', response.data);
你会得到你期望的 .