What is the difference between updated hook and watchers in VueJS?

I open VueJS, and I definitely don’t understand the difference between updatedand observers.

Updated hook

This is a life cycle hook. According to the official documentation , it runs whenever data changes. Therefore, whenever propor data(value, not just a pointer) is updated updated.

Watchers

In the documentation, observers are compared with calculated properties. But in what cases would it be better to use updated ones instead of observers?

It seems that in both cases the DOM is not updated when calling callback ( nextTick()required if we want to manipulate the changes in the DOM). The only difference I see is that it watchersonly works when updating one exact property (or data), where it is always called updated.

I can’t understand what advantages of updating are updated when data ( updating) changes , if we can be more precise ( watchers).

Here are my thoughts.

Thank:)

+4
source share
2 answers

DOM. . DOM , , . updated .

+2

, hook beforeUpdate. updated DOM, beforeUpdate DOM. , .


? (...) , , (updated), (watch).

, updated, , , updated hook, DOM (. ).


Vue 2.0 watch vs. updated:

, vm.$watch, , . , . , , prop.

- DOM , updated hook.

+4

Source: https://habr.com/ru/post/1681006/


All Articles