I'm new to VueJS, I want to ask how can I update the money when the model changed (sum of money and model) then return back the money to html.
<div class="mb-4" v-for="(item, index) in persons" :key="index">
<div class="flex items-center justify-between">
<label :for="'person-'+item.id">{{ item.name }}</label>
<p>{{ item.money }}</p>
</div>
<input v-model="item.model" :id="'person-'+item.id" type="number">
</div>
let app = new Vue({
el: '#app',
data() {
return {
persons: [{
id: 1,
name: 'John',
money: 1000,
model: ''
},
{
id: 2,
name: 'Alex',
money: 5000,
model: ''
},
{
id: 3,
name: 'Katie',
money: 2500,
model: ''
}]
}
},
watch: {
'persons.model'(newVal, oldVal) {
console.log(newVal)
}
}
});
This is my codepen: https://codepen.io/LinhNT/pen/abOymrg
Thank you.