[Vuejs]-Watch computed properties in vuejs

0đź‘Ť

You can’t “watch” a computed value because a computed value is already dynamic.

If you want to perform some logic basic on a computed value, then just use it to do so:

<h1 v-if="isEllipsisActive">{{ title }}</h1>

You don’t need to “watch” your computed value just to set yet another boolean.

0đź‘Ť

you can try this way and see if trigger the watch for you

watch: {
  isEllipsisActive: {
     deep: true
     handler(now){
        this.h1 !== null && console.log('changed')
     }
}

since your computed value is in the same component that you are trying to watch the change performed you should not need to do that. Or you can watch one of the values and perform all the logic you need inside the watcher. But As @Dan say in another comment, sometimes we need to watch those computed values. I use this logic when I want to execute extra code after the computed getter from Vuex trigger changes.

Leave a comment