0

I am having an issue with watched property in Vuejs. The error i am getting - Cannot read property 'list' of undefined even though the list is defined. I am getting the error after it does the if check (at the var index .... line).

watch: {
   selectedRole: () => {
     if (this.modifiedUser.list) {
        var index = this.modifiedUser.list.findIndex(obj => obj.id == 
               this.selectedObj);
        this.modifiedUser.list[index].object = Object.assign({}, this.selectedObj);
  }
}

Any idea why it passes the check in the if statement but fails on the next line?

VueJs - v2.5.2.

Fima Taf
  • 929
  • 9
  • 22

1 Answers1

0

In if (this.modifiedUser.list) { try check if modifiedUser is undefined, please.

Check also if index isn't undefined after:

var index = this.modifiedUser.list.findIndex(obj => obj.id == this.selectedObj);

Hope this helps