Vue.js 2.6 – Vue.observable(object)
This is the third post in the series about the 2.6 version of Vue.js. The first two posts can be found here:
In Vue 2.6, a new method was added to the Vue object: Vue.observable(object). The official documentation can be found at https://vuejs.org/v2/api/#Vue-observable.
The method takes an object as the argument and returns the “same” object, but reactive. An important note about the returned object is that, with versions 2.x of Vue, the object returned by the method is indeed the same, but in future, with Vue 3.x, the behavior will change, and the returned object will be a reactive proxy. So, the recommendation, for compatibility sake, is to use always the object returned.
Let’s see an example:
We have created a reactive object, “state”. After that, updating the object is reflected in the template!