I have a query v-for
which brings me matches of n day. For each game I have two input
where the user will mark the result, I need the v-model
of said input
to be dynamic.
HTML
<template>
<div class="container">
<div class="content">
<form @submit.prevent="validateBeforeSubmit">
<table class="table">
<thead>
<tr>
<th><abbr title="Position">Local</abbr></th>
<th><abbr title="Played">Pronostico</abbr></th>
<th><abbr title="Played">-</abbr></th>
<th><abbr title="Won">Pronostico</abbr></th>
<th><abbr title="Drawn">Visitante</abbr></th>
</tr>
</thead>
<tbody>
<tr v-for="match in matchdays">
<th>
<figure class="image is-32x32">
<img :src="'/img/shield/'+match.teamlocal.shield">
</figure>
{{ match.teamlocal.name }}
</th>
<th>
<div class="field has-addons">
<p class="control">
<input class="input" v-model.number="local"
type="number" placeholder="0">
</p>
</div>
</th>
<th> - </th>
<th>
<div class="field has-addons">
<p class="control">
<input class="input" v-model.number="visitante"
type="number" placeholder="0">
</p>
</div>
</th>
<th>
<figure class="image is-32x32">
<img :src="'/img/shield/'+match.teamvisitante.shield">
</figure>
{{ match.teamvisitante.name }}
</th>
</tr>
<tr>
<td colspan="5" class="tdcolspan5">
<div class="block">
<button class="button is-success" type="submit">
<span class="icon is-small">
<i class="fa fa-check"></i>
</span>
<span>Save</span>
</button>
<!--<a class="button is-success">
<span class="icon is-small">
<i class="fa fa-check"></i>
</span>
<span>Save</span>
</a>-->
</div>
</td>
</tr>
</tbody>
</table>
</form>
{{ $data }}
</div>
</div>
</template>
javascript
<script>
export default {
data () {
return {
matchdays: [],
local: 0,
visitante: 0
}
},
created () {
this.getMatches()
},
methods: {
getMatches () {
axios.get('/api/v1/matchday/'+this.$route.params.matchday )
.then(response => {
this.matchdays = response.data.matchdays.matches
})
},
validateBeforeSubmit() {
this.$validator.validateAll().then(() => {
console.log("ok")
}).catch(() => {
console.log('fallo');
// eslint-disable-next-line
//alert('Correct them errors!');
});
}
}
}
</script>