vue3中使用store.dispatch
时间: 2023-09-09 14:11:06 浏览: 291
在Vue3中,使用`store.dispatch`是用来触发一个action的方法。在引用中的示例中,`store.dispatch('user/sum_actions', sum)`表示触发名为`sum_actions`的action,同时传递参数`sum`给它。这样可以在action内部执行异步操作或者对state进行更改。通常情况下,actions和mutations是配合使用的,mutations用来修改state的值,而actions则可以包含异步操作或者多个mutations的调用。在实际开发中,我们可以在组件中通过`this.$store.dispatch`来触发一个action。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [vuex中store存储store.commit和store.dispatch的用法](https://download.csdn.net/download/weixin_38742453/12924867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [vue3使用vuex](https://blog.csdn.net/CHENC0518/article/details/127707338)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文