我有这个Vuex 2店:无法添加到Vuex商店正确
const datastore = new Vuex.Store({
state: {
socketcluster: {
connection: false,
channels: []
},
selected_offers: []
},
mutations: {
addOffer: function(offer) {
datastore.state.selected_offers.push(offer) // first problem: cannot just use state.offers as it throws an undefined
}
},
getters: {
getOffers: function(){
return datastore.state.selected_offers;
}
}
});
而一个Vue公司2组件内我做的:
methods: {
clicked: function(){
console.log("Toggle Offer");
if (datastore.getters.getOffers.filter(function(o){ o.id == this.offer.id }).length == 0) {
// add it
datastore.commit('addOffer', this.offer)
} else {
// TODO remove it
}
}
}
会发生什么事是,当我触发法,店内变化如下:
我在做什么错?
真棒。不知道我怎么错过了。猜猜我从来没有看过实际的参数。 –