簡體   English   中英

提交突變,但狀態未更新

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM