How to fix watch not triggering with Vue.js?

Sometimes, we want to fix watch not triggering with Vue.js.

In this article, we’ll look at how to fix watch not triggering with Vue.js.

How to fix watch not triggering with Vue.js?

To fix watch not triggering with Vue.js, we should make sure we update object or array contents with this.$set.

For instance, we write

this.$set(this.someObject, 'b', 2)

to update the someObject.b property to 2 and trigger a re-render by calling this.$set with the reactive property, property name, and the value to set for the property respectively.

We can replace the first 2 arguments with arrays and the index of the array entry we want to update also.

Conclusion

To fix watch not triggering with Vue.js, we should make sure we update object or array contents with this.$set.