My requirement is something like this.
- I am rendering a question paper from an object using v-for.
- Once the user select an answer for a question, the question number (index) has to be v-model with that answer. How can I achieve this? this is my code.
<template lang="html">
<div class="container">
<div class="" v-for="(question,index) in questions">
<h1>Question {{index}}</h1>
<p>{{question.question}}</p>
<input type="radio" name="index" value="1">{{question.answer1}}<br>
<input type="radio" name="index" value="2">{{question.answer2}}<br>
<input type="radio" name="index" value="3">{{question.answer3}}
</div>
<hr>
<button type="button" name="button" class="btn">Save and Submit</button>
</div>
</template>
<script>
export default {
data(){
return{
questions:[
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"},
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"},
{question:"what is the capital of france?",answer1:"paris",answer2:"normandy",answer3:"rome"}]
}
}
}
</script>