Я пытаюсь создать тест, используя vue. js, и не могу понять, как заставить кнопку «Далее» повторять мои данные. Надеемся, что на экране отобразится объект, содержащий вопрос с ответами (т. Е. QuestionOne, questionTwo), а затем будет показан следующий объект при нажатии кнопки «Далее». У меня есть несколько попыток в существующем коде, как вы увидите, но ни одна из них не работает.
Шаблон компонента теста:
<template>
<div class="quiz-container">
<div
class="question-container">
<h1> {{ currentQuestion.q }} </h1>
</div>
<div class="answer-container">
<v-btn
v-for="answer in currentQuestion.ans"
:key="answer"
outlined
block
x-large
class="answer-btn"
>
{{ answer }}
</v-btn>
</div>
<div
class="navigation flex-row"
>
<v-btn text x-large @click="questionNav.curr--">Back</v-btn>
<v-spacer />
<v-btn text x-large @click="qNext()">Next</v-btn>
</div>
</div>
</template>
Скрипт теста:
<script>
import { mapGetters } from 'vuex';
export default {
name: 'quiz',
computed: {
...mapGetters('user', {
loggedIn: 'loggedIn'
})
},
data: () => ({
curr: 0,
currentQuestion: {
q: 'kasjdn' ,
ans: ['1', '2', '3']
},
questionOne: {
q: 'How many minutes do you want to spend?' ,
ans: ['Short (15-20)', 'Medium (20-40)', 'Long (40-60)']
},
questionTwo: {
q: 'What muscle group do you want to focus on?' ,
ans: ['Upper Body', 'Lower Body', 'Core', 'Full Body']
},
questionThree: {
q: 'What level intensity do you want?' ,
ans: ['Leisure Walking', 'Speed Walking', 'Jogging', 'Sprinting']
},
questionParts: [this.questionOne, this.questionTwo, this.questionThree]
}),
methods: {
questionNav: function () {
questionParts = [this.questionOne, this.questionTwo, this.questionThree]
currentQuestion = questionParts[curr]
},
qNext: function () {
this.currentQuestion = this.questionParts[this.curr++]
}
}
}
</script>
Как вы видите, я пробовал метод "qNext" и метод "questionNav", но ни один из них не работает. Опять же, я бы хотел, чтобы «Next» перебрал [questionOne, questionTwo, questionThree]. Я относительно новичок в vue, поэтому любая помощь будет принята с благодарностью. Спасибо!