Skip to content

Instantly share code, notes, and snippets.

@lovemycodesnippets
Last active February 7, 2025 17:27
Show Gist options
  • Save lovemycodesnippets/8ffd5d0f60971c476eb57809f00f4c75 to your computer and use it in GitHub Desktop.
Save lovemycodesnippets/8ffd5d0f60971c476eb57809f00f4c75 to your computer and use it in GitHub Desktop.
From the article "Building a Quiz App with Nuxt and Xata"
<script setup>
const props = defineProps({
questions: Array,
answers: Array,
});
const getAnswersForQuestion = (questionId) => {
return props.answers.filter((answer) => answer.question.id === questionId);
};
</script>
<template>
<div class="questions-ctr">
<div class="progress">
<div class="bar"></div>
<div class="status">1 out of 3 questions answered</div>
</div>
<div
class="single-question"
v-for="question in questions"
:key="question.id">
<div class="question">{{ question.question_text }}</div>
<div class="answers">
<div
class="answer"
v-for="answer in getAnswersForQuestion(question.id)"
:key="answer.answer_text">
{{ answer.answer_text }}
</div>
</div>
</div>
</div>
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment