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

时间:2020-05-09 16:59:12

标签: vue.js vuex nuxt.js apollo-client 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,
          },
        })
    }

谢谢!

2 个答案:

答案 0 :(得分:3)

您应该可以这样访问它:

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

签出https://github.com/nuxt-community/apollo-module

答案 1 :(得分:1)

因为我在我的 nuxt apollo 插件中注入了 apolloProvider,

inject("apollo", apolloProvider);

然后在我的情况下,我使用,

export default {
  actions: {
    foo (store, payload) {
        let apolloClient = this.$apollo.defaultClient
    }
  }
}