Skip to content
Advertisement

Vuejs Es6 class reactivity

i’m trying to have a computed property in vuejs associated to a es6 class. My Vue instance looks like this:

JavaScript

My class looks like this

JavaScript

If i try to do something like that:

JavaScript

but the setter is never called, like the reactivity has been lost and i don’t understand why.

I also try:

JavaScript

I pass customClass as a prop, but even creating a new instance directly in the component it doesn’t change the result.

In vuejs docs i don’t recall a section talking about reactivity problem in es6 class, so i was wondering if someone know why and how to make my class reactive.

Thanks in advance

Advertisement

Answer

The setter of a computed property, say myComputedProperty, is triggered when you assign to that property (e.g. this.myComputedProperty = {something: 'else'}.

What you probably are looking for is a watcher, more specifically, a watcher with deep: true, such as:

JavaScript

Demo below.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement