I have code below that fetches data from an API. Here, the questions part is showing good, but, when it comes to the answers, the error mentioned above shows and it crashes the app.
The first time I built it in App.vue
, it was working fine, but, when I move it to a view page, it crashes. Any idea on how to solve this?
<template>
<div class="container-question" width=800px>
<b-row>
<b-col cols="8">
<h1> Recently Asked </h1>
<ul
v-for="(question1,index) in questions"
:key="index"
:question1="questions[index]"
>
<li>
{{ question1.question }}
<b-row id="asked-info">
<p>Asked by: </p>
<div
id="user"
v-for="(answer, index) in answers"
:key="index"
>
{{ answer }}
</div>
</b-row>
<b-row>
<b-button class="outline-primary" style="margin:auto;">
Answer
</b-button>
</b-row>
</li>
</ul>
</b-col>
</b-row>
</div>
</template>
<script>
export default {
data() {
return {
questions: [],
index: 0,
}
},
computed: {
answers() {
// here is the problem it can't read the correct_answer and shows the error
let answers = [this.question1.correct_answer];
return answers;
},
},
mounted: function() {
fetch('https://opentdb.com/api.php?amount=10&category=9&difficulty=medium&type=multiple', {
method: 'get'
})
.then((response) => {
return response.json()
})
.then((jsonData) => {
this.questions = jsonData.results
})
}
}
question1
? – Boussadjra Brahimprops: ['question1']
– Daniel_Knights