vue-chat icon indicating copy to clipboard operation
vue-chat copied to clipboard

dispatch为什么可以用来提交mutation

Open HiKWang opened this issue 6 years ago • 1 comments

请问store.js中的这段代码,为什么mutation是用dispatch在提交呢? dispatch不是用来分发action的吗?commit才是用来提交mutation的啊。

// store.js
export const actions = {
    initData: ({ dispatch }) => dispatch('INIT_DATA'),
    sendMessage: ({ dispatch }, content) => dispatch('SEND_MESSAGE', content),
    selectSession: ({ dispatch }, id) => dispatch('SELECT_SESSION', id),
    search: ({ dispatch }, value) => dispatch('SET_FILTER_KEY', value)
};

HiKWang avatar Oct 02 '18 02:10 HiKWang

dispatch是用来异步操作的,先熟悉下文档吧!

CJcrazycool avatar Dec 18 '18 12:12 CJcrazycool