[Vuejs]-VueJS data initialization for non existent objects

0👍

First of all, an empty array is still "truthy", so your check here

v-bind:dataid="myobject ? myobject.data_id : 0"

always returns true. You should check for myobject.length instead. Your code should work now.

Also, you really don’t need to define dummy objects for an array. Vue detects whenever you mutate an array.

https://v2.vuejs.org/v2/guide/list.html#Array-Change-Detection

Leave a comment