Vue.js: length of the watch array

How to view array length using Vue.js?

+4
source share
1 answer

Use the clock 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 view the calculated length attribute:

vm.$watch('item_length', function(newVal, oldVal) {
    console.log('caught!');
});
+8
source

All Articles