使用 NUXT 中的 vue-apollo 从 Vuex 商店访问 this.$apollo?

ctw*_*ome 2 vue.js vuex apollo-client nuxt.js vue-apollo

我想在 vuex 商店中存储来自登录操作的用户。但是没有访问权限this.$apollo

export const actions = {
  UPSERT_USER({ commit }, { authUser, claims }) {
     this.$apollo
        .mutate({
          mutation: UPSERT_USER_MUTATION,
          variables: {
            id: user.uid,
            email: user.email,
            name: user.name,
            picture: user.picture,
          },
        })
    }
Run Code Online (Sandbox Code Playgroud)

谢谢!

ajo*_*obi 6

您应该能够像这样访问它:

export default {
  actions: {
    foo (store, payload) {
      let client = this.app.apolloProvider.defaultClient
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

查看https://github.com/nuxt-community/apollo-module