Home  >  Article  >  Web Front-end  >  Which one is executed first, watch or mounted in vue?

Which one is executed first, watch or mounted in vue?

下次还敢
下次还敢Original
2024-04-28 00:21:12468browse

mounted is executed first. The execution order of Vue life cycle hooks is: created, beforeMount, mounted, watch, beforeUpdate, updated, beforeDestroy, destroyed; the mounted hook is executed before the watch option.

Which one is executed first, watch or mounted in vue?

Which one is executed first, watch or mounted, in vue?

Answer: mounted

Detailed explanation:

mounted is a Vue life cycle hook. When a Vue Fired when an instance is created and mounted to the DOM. watch is a Vue option used to monitor changes in data properties and execute callback functions when they change.

Therefore, the mounted hook will be executed before the watch option. This is because in the life cycle of Vue, the created, mounted, beforeUpdate, updated, beforeDestroy and destroyed hooks are triggered in sequence, and the watch option is executed after the mounted hook.

Process:

  1. created(): Create a Vue instance.
  2. beforeMount(): Prepare to mount to DOM.
  3. mounted(): Mounted to DOM. At this stage, the mounted hook is triggered.
  4. watch(): Monitor changes in data attributes.
  5. beforeUpdate(): Before the data attribute changes.
  6. updated(): After the data attribute has changed.
  7. beforeDestroy(): Before the component is destroyed.
  8. destroyed(): The component is destroyed.

The above is the detailed content of Which one is executed first, watch or mounted in vue?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn