NicolaL1995
NicolaL1995

Reputation: 17

differences between beforeUpdate and watch Vue3

Im actually learning Vue3. It seems generally very clear to me. But one thing is not clear at all. The differecens between watch and beforeUpdate. There are differences between this two? And if yes, when is preferred use one rather than another?

Upvotes: 0

Views: 264

Answers (3)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

Yes there are many differences. Watch observes only changes in the reactive data passed as the first argument, so it only operates after the monitored properties have changed. As for beforeUpdate , it is a life cycle that is called before the DOM is changed due to reactive data changes in the component, So it observes any reactive data in the component.

Upvotes: 1

Gabor Angyal
Gabor Angyal

Reputation: 2255

With beforeUpdate you can listen to any change in the component. It will be called if any of the reactive elements change that is used in rendering the component. With watch you can listen to specific reactive elements, even if they are not used in rendering the component.

Upvotes: 0

AliRjbzdeh
AliRjbzdeh

Reputation: 19

i think watch will triggerd after changing the data but beforeUpgrade is a hook and will look at the DOM for runnig something

Upvotes: 0

Related Questions