繁体   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