1

I want a two dimensional array which will have dynamic key and array of objects pushed to it, as you see I tried this.$set and Vue.set but got no success so far,

data() {
rep_recs: [] , // I want this array reactive..so I can display a table
recs:[] // actual data
},
created() {

    while(cond) {
                   //..some code
                   var y_m_key = `${Y}-${M}`

                   //  Vue.set(this.rep_recs, y_m_key,  [])
                   // this.$set(rep_recs, y_m_key,  [])
                   this.rep_recs[y_m_key] = []


                    for (var i=0; i<this.recs.length; i++) {
                        var rec = this.recs[i]
                        this.rep_recs[y_m_key].push(rec) //this works but not reactive
                    }
    }
}

1 Answer 1

3

this should work for you

var rec = this.recs[i]
this.$set(this.rep_recs, y_m_key, [
    ...this.rep_recs[y_m_key],
    rec
]);

This creates a new array everytime, which should solve the reactivity issue

Sign up to request clarification or add additional context in comments.

2 Comments

ah!!..I hoped this would definitely work..it throws an error.. " Cannot convert undefined or null to object"
@CodeTree if you have a working example somewhere, i might be able to help with debugging

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.