0

please help with .$set data on vue , after read docs of vuejs.org I did not realize what must be index in $set when my data is already null and also syntax I need to write. please provide the syntax need for set data in this specific example. thank you.

//in vue js components:
data() {
    return {
      columnDefs: null
    };
computed: {
    onLoadColumns() {
      // some logic here (manipulate received props from parent)
      // logic bring this [{},{},{}]
      // sth = [{},{},{}]

      // now want to .$set() , (or maybe $add()) that array to data obj for reactivity.

      // what syntax look like? this below didn't work.
      this.$set(this.columnsDef, 0, sth);
    }

3
  • It is not clear what you are asking about. Are you talking about setters and getters ? Commented Aug 23, 2019 at 4:48
  • i want add array of objects to my data. i have no idea how do that. Commented Aug 23, 2019 at 4:49
  • stackoverflow.com/questions/57615156/… - [] instead null Commented Aug 23, 2019 at 4:52

1 Answer 1

0

You have a typo: should be this.$set(this.columnDef, 0, sth);. Not this.columnsDef - without s.

Also try to init you columnDef with [] in data:

data() {
  return {
    columnDefs: []
  }
},

Or set empty array right before assigning to zero index:

this.columnDef = []
this.$set(this.columnDef, 0, sth)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks that worked with empty array but docs say must not do that (ag-grid) any way thanks.

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.