【问题标题】:How to access this.$apollo.query in the Vuex store with Nuxtjs?如何使用 Nuxtjs 在 Vuex 商店中访问 this.$apollo.query?
【发布时间】:2020-10-29 20:44:19
【问题描述】:

不断收到未定义的查询...谁能告诉我如何使用 Nuxtjs 在 Vuex 商店中访问 this.$apollo.query?

import gqlGetAllTags from '~/apollo/queries/gqlGetAllTags.gql'

@Module({
  stateFactory: true,
  namespaced: true,
  name: 'products',
})
export default class Products extends VuexModule {
  product: Array<object> = []

  @Mutation
  GET_PRODUCT(product: Array<object>) {
    this.product = product
  }

  @Action({ rawError: true })
  async getProduct() {
    const collection = await this.$apollo.query({
      query: gqlGetAllTags,
      variables: {
        handle: 'nirvana',
      },
    })
    this.context.commit('GET_PRODUCT', collection)
  }
}

【问题讨论】:

    标签: javascript vue.js vuejs2 vuex nuxtjs


    【解决方案1】:

    您可以像这样在 Vuex 操作中使用 Appolo 提供程序。

    const collection = await this.app.apolloProvider.clients.defaultClient
      .query({
        query: gqlGetAllTags,
        variables: {
          handle: 'nirvana',
        },
      })
    

    【讨论】:

      猜你喜欢
      • 2018-05-19
      • 2020-08-25
      • 2020-10-28
      • 2021-09-24
      • 1970-01-01
      • 2021-10-23
      • 2020-12-07
      • 2021-06-03
      • 2017-12-05
      相关资源
      最近更新 更多