How can I watch an array length using Vue.js?
Use the watch section in your vm creation:
var vm = new Vue({
el: 'body',
data: {
items: []
},
computed: {
item_length: function () {
return this.battle_logs.length;
}
},
watch: {
items: {
handler: function () {
console.log('caught!');
},
deep: true
}
}
});
Or watch a computed length attribute:
vm.$watch('item_length', function(newVal, oldVal) {
console.log('caught!');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With