[Vuejs]-Component v for doesn't recognise prop, if not explicitly declared while initializing object in root

2๐Ÿ‘

โœ…

As mentioned in my comment above, Vue cannot detect when you add properties to an object after that object has been added to the Vue. Use $set in your else clause.

pushValue(key, value) {
    var obj = this.accountTypes

    if (obj.hasOwnProperty(key)) {
        var idx = $.inArray(value, obj[key]);
        if (idx == -1) {
            obj[key].push(value);
        }
    } else {
        this.$set(obj, key, [value]);
    }
},

The error you are seeing with respect to a key is likely because you are setting a key during your loop:

<another-component v-for="(x, i) in accounts" :key="x"></another-component>

The problem here is that x is an array. i, however is just the key of accounts, so use that.

<another-component v-for="(x, i) in accounts" :key="i"></another-component>
๐Ÿ‘คBert

Leave a comment