When the vuex state data is an array or object, the data is updated and the view is not updated.

state(){
        return{

                filterParams:[] /** set array */
        }

} ,
mutations: {
        updateFilterParams(state,res){
                let filterParams=state.filterParams;
                let len=filterParams.length;

                if(!len){

                        state.filterParams.push(res);

                }else{
                        let key=filterParams.findIndex(e => e.name === res.name);
                        if(key>=0){

                                /**Direct assignment will not trigger the getter method to refresh*/
                                //state.filterParams[key]=res;
                                /***Convert the object, and then re-assign, it can be resolved*/
                                state.filterParams[key ]=JSON. parse(JSON. stringify(res));
                         }

                }

        }
}

Component monitoring: need to add deep:true .

watch(() => store.state.filterParams,(ov,nv)=>{

       /**Related monitoring code**/

      },{deep:true});

Guess you like

Origin blog.csdn.net/pinhmin/article/details/130322023