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?
CodePudding user response:
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.
CodePudding user response:
i think watch will triggerd after changing the data but beforeUpgrade is a hook and will look at the DOM for runnig something
CodePudding user response:
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.