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

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

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

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="";
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...