[Vuejs]-Vue component's button callback: Cannot read properties of undefined

1👍

There’s no this (that refers to component instance as in options API) in script setup syntax, you should use computedVar.value instead of this.computedVar :

function displayWhatever( index: number): void {
  selected.value = index;
  event('myCustomEvent', {
    value1: myComputedVar.value[index].value1,
    value2: myComputedVar.value[index].value2
  })
}

0👍

In a setup (composition api), You won’t need this keyword. Also, modify the displayWhatever function parameter. It should accept only one parameter, Hence remove this.

The value of computed property will be kept in a value property of the created reference. Hence, you should access it by using .value instead of this.

function displayWhatever(index: number): void {
  selected.value = index;
  event('myCustomEvent', {
    value1: myComputedVar.value[index].value1,
    value2: myComputedVar.value[index].value2
  })
}

Leave a comment