Multiple radio Vue.js
by RomainMazB
HTML
<div id="app">
<button @click="fetchDatas">Click me!</button>
<template v-if="resultObject.length">
<div v-for="(data, index) in resultObject">{{ data.id }}: {{ data.name }} <br>
<input type="radio" v-model="radios[index]" :name="'radios-'+index" value="Presente">Presente</input>
<input type="radio" v-model="radios[index]" :name="'radios-'+index" value="Ausente">Ausente</input>
/// Value: {{ radios[index] }} </div>
</template>
</div>
JavaScript
new Vue({
el: '#app',
data: {
resultObject: [],
radios: []
},
methods: {
fetchDatas() {
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(data => {
console.log('test: '+data.length);
this.resultObject = data;
});
}
}
});