0

I have some variables

data() {
    return {
      resData: {},
      datData: {},
      .....
    };
},

then I have method that need to assign values to resData and etc.
If name has value of resData then I need to assign value to the variable.

methods:{
  chgValue(name){
      if (name == 'resData') this.resData = 1;
      elseif .....
      else
  }
}

Instead of doing multiple if else statements, I'm trying to do something:

methods:{
  chgValue(name){
      this.window[name] = 1;
  }
}

But I receive error

TypeError: Cannot set property 'resData' of undefined

Any ways that i could achieve the method ?

hatched
  • 795
  • 2
  • 9
  • 34
  • 2
    It should be `this[name] = 1`. Not sure where you got `window` from. Even better would be `this.$set(this, name, 1)`, that way you're guaranteed to be setting a reactive property – Phil Dec 09 '19 at 09:19
  • @Phil yes u r right, i found the `window` from other threads for using reference variable – hatched Dec 09 '19 at 09:28
  • 1
    I can see where you got that from. I hope the linked post makes sense for you – Phil Dec 09 '19 at 09:30

0 Answers0