Eight created mounted updated destroyed are commonly used, and three activated deactivated errorCaptured are rarely usedCopy the code
-
BeforeCreate (called before instance creation) At this point, the data observation event configuration has not yet started
-
Created (called when the instance is created) At this point, the instance is configured for data observation, property and method operations, and watch/ Event event callbacks.
-
BeforeMount (called before the instance is mounted to the container) At this point, the Render function is called for the first time. The example completes the following configuration: compile the template, and generate HTML from the data inside the data and template. Mounted el is mounted after the instance is mounted
-
Mounted The instance completes the following configuration: Replace the DOM object pointed to by the EL attribute with the above compiled HTML content. Render THE XML from the template into an HTML page. The virtual DOM becomes the real DOM
-
BeforeUpdate (called before data is updated) occurs before the virtual DOM is patched.
-
Updated (invoked after data is updated) Is invoked after the virtual DOM is re-rendered and patched due to data changes. When called, the component DOM is already updated, so DOM-dependent operations can be performed. In most cases, however, you should avoid changing the state during this period, as this can lead to an infinite update loop
-
Activated Keep-alive is invoked when the activated component is activated
-
Deactivated When the keep-alive component is disabled
What is the VUE lifecycle
A: The lifecycle of a Vue instance is the process from creation to destruction. The life cycle of a Vue is a series of processes from the beginning of creating, initializing data, compiling templates, mounting Dom, rendering, updating, rendering, and destroying
How many phases are there in the VUE life cycle?
A: It can be divided into 8 stages altogether: before/after creation, before/after loading, before/after update, and before/after destruction
Which hooks are triggered the first time the page loads?
A: Generates beforeCreate, created, beforeMount, mounted
In what cycle is DOM rendering completed?
A: DOM rendering is done in Mounted
V-if V-show updated hook
Answer: V-if triggers the updated hook because the data has changed and the instance detects the change, it raises beforeUpdate and then updates both hooks.
- V-if: Indicates the initial setting for a component
v-if:false
The component will not render and the lifecycle hook will not execute whenfalse => true
Component will be rendered, and in turn to the execution of the component beforeCreate created, beforeMount, mounted hooks, andtrue => false
Execute beforeDestroy, Destroyed hooks in sequence - V – show: one will be executed in sequence full lifecycle beforeCreate, created, beforeMount, mounted
When is the AJAX request proposal initiated?
A: created the difference between the phase of the ajax requests and mounted request: the former page view, if the request letter blog.csdn.net/sunhuaqiang…
Mounted Are subcomponents mounted at the same time?
A: Simultaneous mount is not promised, but if you want to wait until the entire view is rendered, you can use vm.$nextTick
The use of this $nextTick
Blog.csdn.net/sunhuaqiang…
Why do prop changes sometimes not trigger updated?
Online sample
- A change in view would bring
updated
The trigger - In this case, if the child component
Virtual dom
The same. In short, yoursprop
Content is not bound to the view, thenupdated
It doesn’t trigger