axios of Vue request initialization data on the Created or Mounted?

First Life Cycle Analysis

beforecreated: el and data did not initialize 
created: the completion of the initialization data data, el no 
beforeMount: el completed and data initialization 
mounted: mount complete

 

(1)mounted

  A lot of people told me that initialization Mounted on the inside, I asked her (him) Why? She (he) answered, because this time they initialize DOM rendering okay. Then I continue to ask DOM rendering and initialization request initialization data What is the relationship? They say you can display data request out of it. (I think there contradictions?)

DOM rendering and initialization request to initialize the data and there is no conflict

  Let's take a look at the life cycle of the previous Vue

  : A, beforeCreate
    (instance is called before after initialization, the data observed (data observer) and event / watcher event configuration .--- official paste)

    

 

   b、beforeMount:

    (To be called before mounting the beginning: the first related to the render function is called .--- official stickers)

    

 

   

We saw the two continue to analyze:

We request initialization data back or the underlying data is not required in Data hanging above the Vue? (Yes, we need √) 
and then we continue beforeCreate when Data have not been generated? (The answer is: No ×.)
 - so this step is not linked to the data of Data Vue above 
then I continue to look created when Data have not been generated? (The answer is: it generates .√)
 - so this is a step we can hang data to the Data Vue above, is not to put the matter here?
- Yes, it can be placed here. So the final conclusion is created on the inside.

 

Supplementary analysis:

(1)mounted

  If all requests created on the inside, too many requests will load the page will lead to slow a brief black and white situation, I usually write on it, no complicated interfaces created will be put inside, interfaces and more complex, it will be mounted on inside.

(2)mounted

  created is loaded DOM, after the html executed immediately, such as initialization, take a screen height adjustment, assignment, etc., and is mounted after the execution, including js, ready to call a method that is similar to the traditional development as the first load and then call jquery plugins

 

 

 

.

Guess you like

Origin www.cnblogs.com/jianxian/p/11938752.html