vue中对于公共数据,需要共享数据一般存储在store中
在store中存在action及mutations去修改state中的数据
dispatch是去触发actions中的方法
commit是去触发mutations 中的方法
主要区别:
dispatch:含有异步操作,数据提交至 actions ,可用于向后台提交数据
代码: this.$store.dispatch('isLogin', true);
commit:同步操作,数据提交至 mutations ,可用于登录成功后读取用户信息写到缓存里
代码: this.$store.commit('loginStatus', 1);