Reputation: 17
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
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
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
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