vuex里面的this.$store.dispatch 和 this.$store.commit用法以及区别

两个方法都是传值给vuex的mutation改变state

dispatch:异步操作,数据提交至 actions ,可用于向后台提交数据

this.$store.dispatch('isLogin', true);

commit:  同步操作,数据提交至 mutations ,可用于登录成功后读取用户信息写到缓存里

this.$store.commit('loginStatus', 1);

注:必须要用commit(‘SET_TOKEN’, tokenV)调用mutations里的方法,才能在store存储成功。

posted @ 2020-08-26 18:07  小那  阅读(15248)  评论(0编辑  收藏  举报