👉vuex中this.$store.commit和this.$store.dispatch的用法_this.$store.dispatch作用_老电影故事的博客-CSDN博客

目录

区别:

代码实现:


相同:都是传值给vuex的mutation改变state


区别:

this.$store.commit()  同步操作

this.$store.commit('方法名',值)【存储】

this.$store.state.方法名【取值】


this.$store.dispatch()  异步操作

this.$store.dispatch('方法名',值)【存储】

this.$store.getters.方法名【取值】

当操作行为中含有异步操作:
比如向后台发送请求获取数据,就需要使用action的dispatch去完成了。其他使用commit即可。

commit => mutations,用来触发同步操作的方法。
dispatch =>actions,用来触发异步操作的方法。
在store中注册了mutation和action,在组件中用dispatch调用action,然后action用commit调用mutation。
 

代码实现:

👉vuex中this.$store.commit和this.$store.dispatch的用法_this.$store.dispatch作用_老电影故事的博客-CSDN博客 

GitHub 加速计划 / vu / vue
100
18
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:17 天前 )
9e887079 [skip ci] 11 个月前
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐