0
Guys I’m starting with Vue and I’m having a little difficulty. In the image below I have a table with some items and when I will increase the amount of the item Orange for example is increased all other items, as fixed this?
Below my code
new Vue({
el: '#app',
data() {
return {
quantidade: 1,
Opcionais: [
{ Code: 1, Nome: 'Abacaxi', Valor: "50.00" },
{ Code: 2, Nome: 'Abacate', Valor: "50.00" },
{ Code: 3, Nome: 'Morango', Valor: "60.00" },
{ Code: 4, Nome: 'Maçã', Valor: "17.00" },
{ Code: 5, Nome: 'Laranja', Valor: "30.00" }
]
}
},
methods: {
adicionar() {
this.quantidade++
},
remover() {
if(this.quantidade === 0) {
this.quantidade = 0
} else {
this.quantidade--
}
}
}
})
<script src="https://unpkg.com/vue"></script>
<div id="app">
<template>
<div class="usuario-lista">
<table>
<thead>
<tr>
<th>#Code</th>
<th>Nome</th>
<th>Valor</th>
</tr>
</thead>
<tbody>
<tr v-for="(opcional, row) in Opcionais" :key="opcional.Code">
<td>
<button @click="remover">-</button>
<input type="text" :value="quantidade">
<button @click="adicionar(row)">+</button>
</td>
<td>{{ opcional.Nome }}</td>
<td>{{ opcional.Valor }}</td>
</tr>
</tbody>
</table>
</div>
</template>
</div>