Vue.js life cycle

Source: Internet
Author: User

What is the life cycle
The
Vue instance has a complete life cycle, that is, from the beginning to create, initialize the data, compile the template, mount the DOM, render → update → render, uninstall a series of processes, we call this the life cycle of Vue. In layman's terms, the process of creating a Vue instance from creation to destruction is the life cycle.

Throughout the life of Vue, it provides a series of events that allow us to register the JS method when the event is triggered, allowing us to control the overall situation with our own registered JS method, in which the this directly points to the instance of Vue.

It is particularly noteworthy that the difference between the created hook function and the mounted hook function
Each hook function is triggered at what time

Beforecreate

after the instance is initialized, the data observer and Event/watcher event configurations are called.

Created

The
instance is called after it has been created. In this step, the instance has completed the following configuration: Data Observer, properties and method operations, Watch/event event callbacks. However, the Mount phase has not yet started, $el properties are not currently visible.

Beforemount

called before the mount begins: The associated render function is called for the first time.

Mounted

El is newly created VM. $el replaced and mounted to the instance after the hook is called.

BeforeUpdate

called when data is updated, which occurs before the virtual DOM is re-rendered and patched. You can change the state further in this hook, which does not trigger the additional re-rendering process.

Updated

The hook is called after the virtual DOM is re-rendered and patched due to data changes.

When this hook is called, the component Dom has been updated, so you can now perform operations that depend on the DOM. In most cases, however, you should avoid changing the state during this period, as this may result in an infinite loop being updated.

The hook is not called during server-side rendering.

Beforedestroy

called before the instance is destroyed. In this step, the instance is still fully available.

Destroyed

called when the Vue instance is destroyed. Once invoked, everything indicated by the Vue instance will be unbound, all event listeners will be removed, and all child instances will be destroyed. The hook is not called during server-side rendering.
This digest from: https://www.cnblogs.com/superAnny/p/8590896.html

Vue.js life cycle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.