【发布时间】:2020-07-28 13:20:16
【问题描述】:
我正在使用道具来获取鸟类的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
<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>
有没有更好的获取数据的方法?
答案正确
我已经用解决方案更新了 github repo。
【问题讨论】:
标签: vue.js vuex apollo-client nativescript-vue vue-apollo