Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

vuex 内mutation 方法同级互相调用?

 setAlert(state, data){
    console.log(JSON.stringify(data));
    data.btns = data.btns || [];
    state.uiAlert = data;
    store.commit("hideAlert");
},
hideAlert(state){
    state.uiAlert.title=state.uiAlert.msg="";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

尝试在actions里面commit另一个mutation,而不是在mutation里调用另一个mutation方法。

const foo = function(a, b) {
    // 发个异步请求或者做点什么其他的勾当
    commit(mutationA);
    commit(mutationB);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...