【问题标题】:What to do if the data does not reach?数据达不到怎么办?
【发布时间】:2020-07-08 12:08:14
【问题描述】:

我有一个页面index.vue 在此页面上,我有以下代码

<nuxt-link :to="'/user/'+userid">Go to user</nuxt-link>

我们去找用户 到页面user/_id.vue

在此页面上,我正在使用 Graphql 发出请求

export default {
  apollo: {
    user: {
      prefetch: true,
      query: user,
      variables() {
        return {
          id: this.$route.params.id
        }
      }
    }
  },
}
query user($id: Int) {
  user(where: {id: {_eq: $id}}) {
    name
  }
}

如果你点击这个页面上的按钮,那么它会返回给我undefined

mounted() {
    console.log(this.users) // return undefined
  },

对不起我的英语????我该如何解决?

【问题讨论】:

    标签: vue.js graphql nuxt.js apollo-client vue-apollo


    【解决方案1】:

    您可以尝试通过 fetch 记录您的数据。

    export default {
    
    data(){
        return {
            mydata: [],
            query: ''
        }
    },
    fetch() {
        console.log(this);
        console.log(this.users);
      },
    }
    

    https://nuxtjs.org/blog/understanding-how-fetch-works-in-nuxt-2-12/

    我确信还有另一种方法可以通过在您的 apollo 模块设置中使用 watchLoading/errorHandler 来记录数据/数据更改,但我无法让它发挥作用 - 所以我正在使用 fetch。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 2020-08-15
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      相关资源
      最近更新 更多