那个网站做扑克牌便宜,售卖链接,网页设计与制作总结报告,网站开发与设计实训总结两千字Vuex 中的 dispatch 方法是用来触发#xff08;派发#xff09;action 的。store.dispatch(‘actionName’) 会去调用名为 actionName 的 action。
在 Vuex 中#xff0c;actions 类似于 mutations#xff0c;但是可以包含任意异步操作#xff0c;而且 action 不能直接修…Vuex 中的 dispatch 方法是用来触发派发action 的。store.dispatch(‘actionName’) 会去调用名为 actionName 的 action。
在 Vuex 中actions 类似于 mutations但是可以包含任意异步操作而且 action 不能直接修改 state必须通过提交commitmutation 来修改 state。
如果我们调用 store.dispatch(‘resetChatInput’)那么就是触发执行名为 ‘resetChatInput’ 的 action。具体执行什么操作取决于 ‘resetChatInput’ 对应的 action 函数在 Vuex store 中的定义。 例如如果你的 Vuex store 定义如下
export default createStore({state: {input: {prompt: ,quoteChatId: ,refImage: }},mutations: {RESET_CHAT_INPUT(state) {state.input.prompt state.input.quoteChatId state.input.refImage }},actions: {resetChatInput({ commit }) {commit(RESET_CHAT_INPUT)}}
})那么store.dispatch(‘resetChatInput’) 就是触发 ‘resetChatInput’ 这个 action这个 action 会执行一个异步操作在这个例子中没有异步操作然后提交 mutation ‘RESET_CHAT_INPUT’这个 mutation 会重置 prompt、quoteChatId 和 refImage 这三个 state 的值为默认值。