不要在变异处理程序之外对Vuex商店进行变异

时间:2018-12-02 11:44:33

标签: javascript firebase vue.js vuejs2

为什么这不起作用又不行:

  async login ({ dispatch, state }, user) {
    const token = await this.$fireAuth.currentUser.getIdToken(true)

    const userInfo = user

    Cookies.set('access_token', token) // saving token in cookie for server rendering
    await dispatch('setUSER', userInfo)
    await dispatch('saveUID', userInfo.uid)
  },

但这可以正常工作:

  async login ({ dispatch, state }, user) {
    const token = await this.$fireAuth.currentUser.getIdToken(true)

    const userInfo = {
      displayName: "Nicl",
      email: user.email,
      avatar: user.photoURL,
      uid: user.uid,
      emailVerified: user.emailVerified
    }


    Cookies.set('access_token', token) // saving token in cookie for server rendering
    await dispatch('setUSER', userInfo)
    await dispatch('saveUID', userInfo.uid)
  },

我不明白为什么我会得到我觉得是随机的错误?

0 个答案:

没有答案