I am attempting to create a computed property in Vue.js that is associated with an ES6 class. Here is an example of my Vue instance setup:
...
props: ['customClass'],
computed: {
localClass: {
get() {
return this.customClass
},
set (value) {
console.log("changed")
}
}
}
...
This is the structure of my class:
class CustomClass {
constructor () {
this.selected = false
}
}
When I try to modify the selected property like this:
this.localClass.selected = true
The setter function is not being triggered, and it seems like the reactivity has been lost. This behavior is confusing to me.
I have also attempted:
Vue.set(this.localClass, 'selected', true)
Although I pass customClass as a prop, even creating a new instance directly in the component does not change the outcome.
I searched through the Vue.js documentation but did not find any specific section addressing reactivity issues with ES6 classes. Can anyone offer insight on why this might be happening and how to ensure my class remains reactive?
Thank you in advance