Need help understanding lifecycle hooks #11707
Unanswered
roysmith
asked this question in
Help/Questions
Replies: 1 comment 2 replies
-
The second one should always be failing. Here's why:
So what to do? Either stick with your first variation, or: a) use <div v-if="data" class="queue">
{{ data['query']['pages'][0]['revisions'][0]['slots']['main']['content'] }}
</div> b) check for data being non-nullish: <div v-if="data" class="queue">
{{ data ?? data['query']['pages'][0]['revisions'][0]['slots']['main']['content'] }}
</div> a) use optional chaining: <div v-if="data" class="queue">
{{ data?.['query']['pages'][0]['revisions'][0]['slots']['main']['content'] }}
</div> |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've got a stub of an app which makes an API call to wikipedia and displays the result. This version works. I get:
<div class="queue">{{User:DYKUpdateBot/REMOVE THIS LINE}}</div>
which is what I expect (the actual text will vary depending on what's on the page at the time you make the API call). If I move the JSON-unpacking code into the template, as in this version, things break. Sometimes I get the same text, but sometimes it fails with
Queue.vue:24 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'query')
in the browser console. I'm guessing I'm attaching my callback to the wrong life cycle hook, and end up trying to resolve the Promise multiple times?
Beta Was this translation helpful? Give feedback.
All reactions