组件中的Vuex吸气剂未更新

时间:2018-12-11 12:09:23

标签: vue.js store vuex getter

store.state image

这是计算得出的成分的吸气剂:

        computed: {
        get_indicatorsSubMenuButtons(){

            let p = this.$store.getters.get_indicatorsMainMenuButtonActive[0].mainMenuButtonJson;
            let j;
            switch(p) {
                case 'getFuelStock':
                    j = this.$store.getters.get_indicatorsSubMenuButtons[0].indicatorSubFilters;
                    break;
                case 'getFuelSell':
                    j = this.$store.getters.get_indicatorsSubMenuButtons[1].indicatorSubFilters;
                    break;
                case 'getArticleSell':
                    j = this.$store.getters.get_indicatorsSubMenuButtons[2].indicatorSubFilters;
                    break;
            }
            return j;
        },
    },

这是vuex的吸气剂:

        get_indicatorsSubMenuButtons: (state) => {
            let activeMainMenuButton = state.indicatorsMainMenuButtons.filter(item => item.active === true)[0].mainMenuButtonJson;
            let r  = state.indicatorsSubMenuButtons;
            return r;
        },

当我更改每个按钮的活动状态时,存储中的所有数据都在更新,并且也正在获取。但是,只有在安装组件以及更改父菜单的状态时,组件中的此吸气剂才会更新。

vuex中的变异:

        TOGGLE_MARKING_SETTINGS_SUB_MENU_ITEM: (state, payload) => {
            console.log('payload',payload);
            let o = payload.subFilterId,
                n = payload.subFilterName,
                s = payload.active;

            let activeMainType = state.indicatorsMainMenuButtons.filter(item => item.active === true)[0].mainMenuButtonJson;

            //Vue.set(vm.items, indexOfItem, newValue)

            let v = state.indicatorsSubMenuButtons;
            let vf = v.filter(item => item.subTypeName == activeMainType)[0];

            for (var i = 0; i < vf.indicatorSubFilters.length; i++) {



                if(vf.indicatorSubFilters[i].subFilterId == o){

                    Vue.set(
                        vf.indicatorSubFilters[i], 
                        'active', 
                        true
                    );

                } else {

                    Vue.set(
                        vf.indicatorSubFilters[i], 
                        'active', 
                        false
                    );

                };



            };

        },

商店初始化:

import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export const store = new Vuex.Store({
    state: {
        indicatorsSubMenuButtons: [

        ],

0 个答案:

没有答案