关于前端:vuex中-thisstoredispatch-与-thisstorecommit方法的区别

0次阅读

共计 517 个字符,预计需要花费 2 分钟才能阅读完成。

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
————————————————
版权申明:本文为 CSDN 博主「BruceWu_」的原创文章,遵循 CC 4.0 BY-SA 版权协定,转载请附上原文出处链接及本申明。
原文链接:https://blog.csdn.net/qq_4431…

正文完
 0