Answer the question
In order to leave comments, you need to log in
Track input values in Vue.js input?
<div id="app">
<h1>Add user</h1>
<div v-for="(user, index) in users">
<input v-model="user.name">
<input v-model="user.procent">
<button @click="deleteUser(index)">
delete
</button>
</div>
<button @click="addUser">
New User
</button>
<pre>{{ $data }}</pre>
</div>
new Vue({
el: '#app',
data: {
users: [{ name: '',procent:'' }]
},
methods: {
addUser: function () {
this.users.push({ name: '',procent:'' });
},
deleteUser: function (index) {
console.log(index);
console.log(this.finds);
this.users.splice(index, 1);
if(index===0)
this.addUser()
}
}
});
Answer the question
In order to leave comments, you need to log in
{
computed: {
percentTotal() {
return this.users.reduce((acc, user) => acc + user.percent, 0)
},
},
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question