美文网首页
vuex里面的this.$store.dispatch 和 th

vuex里面的this.$store.dispatch 和 th

作者: SY | 来源:发表于2021-09-06 17:43 被阅读0次

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

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

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

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

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

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

    相关文章

      网友评论

          本文标题:vuex里面的this.$store.dispatch 和 th

          本文链接:https://www.haomeiwen.com/subject/xuqywltx.html