首页 > 其他 > 详细

vuex 中 this.$store.dispatch() 与 this.$store.commit()方法的区别

时间:2021-05-19 23:42:35      阅读:45      评论:0      收藏:0      [点我收藏+]

this.$store.dispatch() 与 this.$store.commit()方法的区别总的来说他们只是存取方式的不同,两个方法都是传值给vuex的mutation改变state
this.$store.dispatch() :含有异步操作,例如向后台提交数据,写法:this.$store.dispatch(‘action方法名’,值)
this.$store.commit():同步操作,,写法:this.$store.commit(‘mutations方法名’,值)

commit: 同步操作   用于用户登录退出页面时操作

存储 this.$store.commit(‘changeValue‘,name)
取值 this.$store.state.changeValue
dispatch: 异步操作

存储 this.$store.dispatch(‘getlists‘,name)
取值 this.$store.getters.getlists

vuex 中 this.$store.dispatch() 与 this.$store.commit()方法的区别

原文:https://www.cnblogs.com/jie98/p/14786038.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!