[英]Mutation committed but state not updated
我已經提交了突變,但是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)
}
}
我現在不在這里做什么?
這就是為什么要破壞廣告系列變量並將數字傳遞給突變而不是對象的原因。
嘗試這個
getCurrentCampaign (state, campaign) {
state.currentCampaign = campaign
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.