It doesn't seem to work when using vuex. $store.commit for the first time

I want to assign values to store in the root instance and then get these values in the subcomponent. However, it does not seem to be able to assign a value to store in the root instance.

var store = new Vuex.Store ({

)
state: {
    paramInfos: []

},
mutations: {
    initParamInfos(state,paramInfos) {
        state.paramInfos = paramInfos;
    }
},
actions:{ 
}

});

function(){
var self=this;
self.$store.commit("initParamInfos", data);
}

in devtool, it is an arrary in base. After
commit, it becomes an object that can be expanded wirelessly all the time.

clipboard.png

clipboard.png



:


debugundefined

clipboard.png

clipboard.png

clipboard.png

May.31,2022

Is there no function in

actions

to commit in actions

then dispatch this action

is roughly the following routine. I suggest you take a look at the syntax of vuex

var store = new Vuex.Store({
    state: {
        paramInfos: []
    },
    mutations: {
        initParamInfos(state,paramInfos) {
            state.paramInfos = paramInfos;
        }
    },
    actions:{ 
        getInfo({commit},data) {
            commit('initParamInfos',data)
        }
    }
});
function initData(){
    let mydata = [1,1,1,1];
    this.$store.dispatch('getInfo',mydata);
}

well, I think I know why. I didn't write it correctly when taking the value. I forgot to add state.
this.$store.paramInfos;
this.$store.state.paramInfos;
but why devtool is such a presentation is still not clear.

Menu