vue lifecycle interview questions

1. What is the vue life cycle?

Answer: The process of Vue instance from creation to destruction is the life cycle. That is, a series of processes from starting to create, initializing data, compiling templates, mounting Dom → rendering, updating → rendering, unloading, etc., we call this the life cycle of Vue.

2. What is the role of the vue life cycle?
Answer: It has multiple event hooks in its life cycle, which makes it easier for us to form good logic when controlling the process of the entire Vue instance.

3. How many stages are there in the vue life cycle?
A: It can be divided into 8 stages in total: before/after creation, before/after loading, before/after update, before/after destruction

4. Which hooks will be triggered for the first page load?
A: The hooks beforeCreate, created, beforeMount, mounted will be triggered when the page is loaded for the first time.

5. In which cycle is the DOM rendering completed?
Answer: DOM rendering has been completed in mounted.

6. Briefly describe which scenarios each cycle is suitable for?
Answer: Some ways of using life cycle hooks: beforecreate : You can add a loading event here to trigger created : The event when the initialization is completed is written here. If the loading event ends here, asynchronous requests are also suitable for calling here mounted : mount the element and get the DOM node updated : if the data is processed uniformly, write the corresponding function here beforeDestroy : you can make a confirmation box to confirm the stop event nextTick : operate the dom immediately after updating the data

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325902967&siteId=291194637