为什么阿波罗无法在第一个请求中获取数据?

问题描述 投票:0回答:1

我正在使用道具来获取鸟的ID。

[当我第一次启动该应用程序并单击以进入第二页时,将不会加载数据。它给出以下错误;

JS: [Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"
JS:
JS: found in
JS:
JS: ---> <Detail> at components/Detail.vue
JS:        <Frame>
JS:          <Root>

但是第二次单击按钮后,它会正确加载。


我创建了一个显示该问题的存储库。请在这里检查:github repo

Working graphql playground

<template>
  <Page>
    <StackLayout>
      <Label :text="bird.name" textWrap="true" />
      <Button text="get data" @tap="getData" />
    </StackLayout>
  </Page>
</template>

<script>
import { gql } from "apollo-boost";

export default {
  props: ["birdID"],

  apollo: {
    bird: {
      query: gql`
        query($id: ID!) {
          bird(id: $id) {
            id
            name
          }
        }
      `,
      variables() {
        return {
          id: this.birdID,
        };
      },
    },
  },
  methods: {
    getData() {
      console.log("bird data: ", this.bird);
    },
  },
  mounted() {},
};
</script>

<style></style>

是否有更好的方法来获取数据?

我正在使用道具来获取鸟的ID。当我第一次启动该应用程序并单击以进入第二页时,将不会加载数据。它给出以下错误; JS:[Vue警告]:渲染错误:“ TypeError:...

vue.js vuex apollo-client nativescript-vue vue-apollo
1个回答
0
投票

问题是您的模板

© www.soinside.com 2019 - 2024. All rights reserved.