Access to this.$apollo from Vuex store with vue-apollo in NUXT?

喜夏-厌秋 提交于 2021-02-10 13:59:45

问题


I want to store the user that comes from the login on an action in the vuex store. But there is no access to 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,
          },
        })
    }

Thanks!


回答1:


You should be able to access it like this:

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

Check out the https://github.com/nuxt-community/apollo-module




回答2:


Because I inject apolloProvider in my nuxt apollo plugin using,

inject("apollo", apolloProvider);

Then in my case I access it using,

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


来源:https://stackoverflow.com/questions/61700515/access-to-this-apollo-from-vuex-store-with-vue-apollo-in-nuxt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!