Home > Web Front-end > HTML Tutorial > What is the Vue life cycle

What is the Vue life cycle

一个新手
Release: 2017-10-02 19:41:18
Original
2999 people have browsed it

<p id="app">
  {{name}}
</p>
Copy after login

Vue divides the entire life cycle into stages such as creation, mounting, updating, and destruction. Each stage will provide some 'hooks' for us to do some actions we want to achieve. Learning the life cycle of instances can help us understand the operating mechanism of Vue instances and make better and reasonable use of each hook to complete our business code.

1.beforeCreate: This stage is after the instance is initialized. At this time, the data observation and event configuration are not ready yet, and the data and el in the instance at this time are still underfined and unavailable

2.createD: The hook immediately after beforeCreate is created. At this time, we can read the value of data, but the DOM has not yet been generated, so the attribute el still does not exist.

3.beforeMount: $el at this time is successfully associated with the DOM node we specified

{{name}}

, but at this time {{} }The name inside has not been successfully rendered into the data in our DATA.

4.mounted: The mounting phase is complete. At this stage, the data will be successfully rendered.

5.beforeUpdate: When the data of the Vue instance is modified, Vue will automatically help us update the rendering view. In this process, Vue provides us with the beforeUpdate hook. After detecting that we want to modify the data At this time, the beforeUpdate hook will be triggered before updating the rendered view. We add the ref attribute to the html fragment code to obtain the DOM element.

beforeUpdate(){
    let name = this.$refs.app.innerHTML;
  }
Copy after login

At this stage, the view is not re-rendered and updated.

6.updated: This stage is after updating the rendering view. At this time, the content on the view is read, which is already the latest content.

  updated(){
    let name = this.$refs.app.innerHTML;
  },
Copy after login

7.beforeDestroy: Calling the destroy() method of the instance can destroy the current component. Before destruction, the beforeDestroy hook will be triggered.

8.destroyed: After successful destruction, the destroy hook will be triggered. At this time, the association between the instance and other instances has been cleared, and it has also been unbound from the view. At this time, the value of name is modified. The attempt is no longer updated, indicating that the instance was successfully destroyed.

The above is the detailed content of What is the Vue life cycle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template