深刻认识this.$store.dispatch() 与 this.$store.commit()的区别

关于这个问题,我写博客之前已经在网上查过很多博客。但是,回答很多都很笼统,不怎么清楚。
下面来看一下我的理解。
commit: 同步操作
存储

this.$store.commit('changeValue',name)

取值

this.$store.state.changeValue

dispatch: 异步操作
存储

this.$store.dispatch('getlists',name)

取值

this.$store.getters.getlists

总的来说,他们只是存取方式的不同,两个方法都是传值给vuex的mutation改变state

猜你喜欢

转载自blog.csdn.net/qq_44469200/article/details/103679882