vue-chat
vue-chat copied to clipboard
dispatch为什么可以用来提交mutation
请问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)
};
dispatch是用来异步操作的,先熟悉下文档吧!