Detailed explanation of the difference between Vue life cycle

Detailed explanation of the difference between Vue life cycle

Life cycle classification

Each component of vue is independent, and each component has its own life cycle.

From component creation , data initialization , mounting , updating , and destruction , this is the so-called life cycle of a component.
The specific methods in the component are:
beforeCreate
created
beforeMount
mounted
beforeUpdate
updated
beforeDestroy
destroyed

beforeCreate

It is called after instance initialization and before data observation and event configuration. At this time, the component's options object has not been created, el and data have not been initialized, so methods cannot be accessed.
Methods and data on data, computed, etc.

created

It is called after the instance has been created. At this step, the instance has completed the following configurations: data observation, property and method calculations, watch/event event callbacks, and completed data initialization, but el has not. However, the hanging stage has not started yet, and the $el property is not visible yet. This is a common life cycle because you can call methods in methods, change the data in data, and the changes can be reflected on the page through Vue's responsive binding, get the calculated properties in computed, etc. Usually we can pre-process the instance here

beforeMount (before mounting)

It is called before the hang starts, and the related render function is called for the first time (virtual DOM). The instance has completed the following configurations: compiling the template, generating html from the data in the data and the template, and completing the el and data initialization. Note that it has not yet been hung on the html to the page.

mounted

Mounting is completed, that is, the HTML in the template is rendered to the HTML page. At this time, you can generally do some ajax operations, and mounted will only be executed once.

beforeUpdate

Called before data is updated, before the virtual DOM is re-rendered and patched. Further changes to the state can be made in this hook without triggering an additional re-rendering process.

updated

This hook is only called when the virtual DOM is re-rendered and patched due to data changes. When called, the component DOM has been updated, so operations that depend on the DOM can be performed. However, in most cases, changing the state during this period should be avoided, as this may cause an infinite loop of updates. This hook is not called during server-side rendering.

beforeDestroy

Called before the instance is destroyed, the instance is still fully usable.
In this step, you can also use this to get the instance.
Generally, some reset operations are performed in this step, such as clearing the timer in the component and monitoring the DOM event

destroyed

Called after the instance is destroyed. After the call, all event listeners will be removed and all child instances will be destroyed. This hook is not called during server-side rendering.
The vue instance has released the event listener and DOM binding, but the DOM structure still exists

Execution order (diagram)

insert image description here

This is the end of this article about the detailed explanation of the differences in the Vue life cycle. For more relevant Vue life cycle content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • In-depth understanding of the life cycle comparison between Vue2 and Vue3
  • Detailed explanation of Vue life cycle
  • A brief discussion on the VUE uni-app life cycle
  • In-depth understanding of Vue life cycle
  • A brief discussion on the life cycle of Vue

<<:  Analysis of mysql temporary table usage [query results can be stored in temporary tables]

>>:  Analysis of centos6 method of deploying kafka project using docker

Recommend

CentOS 7.9 installation and configuration process of zabbix5.0.14

Table of contents 1. Basic environment configurat...

How to install the graphical interface in Linux

1. Linux installation (root user operation) 1. In...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

Using puppeteer to implement webpage screenshot function on linux (centos)

You may encounter the following problems when ins...

MySQL 8.0.16 installation and configuration tutorial under CentOS7

Uninstall the old version of MySQL (skip this ste...

Use PHP's mail() function to send emails

Sending emails using PHP's mail function The ...

A brief discussion on JS prototype and prototype chain

Table of contents 1. Prototype 2. Prototype point...

Why not use UTF-8 encoding in MySQL?

MySQL UTF-8 encoding MySQL has supported UTF-8 si...

How can MySQL effectively prevent database deletion and running away?

Table of contents Safe Mode Settings test 1. Upda...

Gallery function implemented by native Js

Table of contents The first The second Native Js ...

A brief discussion on the use of GROUP BY and HAVING in SQL statements

Before introducing the GROUP BY and HAVING clause...

How to use worker_threads to create new threads in nodejs

Introduction As mentioned in the previous article...

HTML+CSS+JS sample code to imitate the brightness adjustment effect of win10

HTML+CSS+JS imitates win10 brightness adjustment ...

What is TypeScript?

Table of contents 1. JavaScript issues 2. Advanta...