Disclaimer: I do not know why the bug described in the question occurs. It may be the v-for causing DOM input values and component private state to become out of sync. Please share if you know the cause of this behaviour
You are right that this.list is being updated correctly. You can see this by logging out the names beside the input fields:
var demo = new Vue({
el: '#demo',
data: {
items: []
},
methods: {
'manage': function(old, new_) {
var i = this.items.length;
while (i--) {
if (!this.items[i]['name']) {
this.items.$remove(this.items[i]);
}
}
}
},
watch: {
'items': {
handler: 'manage',
deep: true
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<div id="demo">
<div v-for="n in items.length + 1">
{{ items[n]['name'] }}
<input v-model="items[n]['name']"/>
</div>
</div>
This can be fixed by calling manage on keyup rather than whenever the list changes.
Here is how to implement similar behavior on keyup:
var demo = new Vue({
el: '#demo',
data: {
items: []
},
methods: {
'manage': function(old, new_) {
var i = this.items.length;
while (i--) {
if (!this.items[i]['name']) {
this.items.$remove(this.items[i]);
}
}
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<div id="demo">
<div v-for="n in items.length + 1">
<input v-model="items[n]['name']" @keyup="manage"/>
</div>
</div>
Also, you're using the minified version of vue. If you use the unminified version you'll see that your code is prompting some warnings. They could be contributing to the unexpected behavior.
v-forto iterate over a range may be causing DOM input values and component private state to become out of sync.