我已提交变异,但currentCampaign
状态未更新而是返回undefined
。以下是截图。
这是商店。
import Vuex from 'vuex'
import Vue from 'vue'
import axios from 'axios'
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
campaigns: '',
currentCampaign: ''
},
actions: {
getCampaigns ( {commit} ) {
axios
.get('/api/campaign/history')
.then((response) => {
commit('GET_CAMPAIGNS', {campaigns: response.data});
})
}
},
mutations: {
GET_CAMPAIGNS: (state, {campaigns}) => {
state.campaigns = campaigns
},
getCurrentCampaign (state, {campaign}) {
state.currentCampaign = campaign
}
},
});
我从组件方法调用变异如下:
methods: {
markAsCurrent (campaign) {
this.$store.commit('getCurrentCampaign', campaign.id)
}
}
我在这里做的不是什么?
答案 0 :(得分:0)
这就是为什么你要对一个广告系列var进行解构并将一个数字传递给突变,而不是一个对象。
试试这个
getCurrentCampaign (state, campaign) {
state.currentCampaign = campaign
}