The life cycle of Vue JS (read it)

Source: Internet
Author: User

With the Vue framework, familiarity with its life cycle can make development better.

First take a look at the official website map, detailed to give the Vue life cycle:

It can be divided into 8 stages altogether:

Beforecreate (before creation),

Created (after creation),

Beforemount (pre-loaded),

Mounted (after loading),

BeforeUpdate (before the update),

Updated (after the update),

Beforedestroy (before destruction),

Destroyed (after destruction)

Then use an example demo to demonstrate the specific effect:

<div id=app>{{a}}</div>

<script>

var Myvue = new Vue ({

El: "#app",

Data: {

A: "Vue.js"

},

Beforecreate:function () {

Console.log ("Pre-creation")

Console.log (THIS.A)

Console.log (this. $el)

},

Created:function () {

Console.log ("After creation");

Console.log (THIS.A)

Console.log (this. $el)

},

Beforemount:function () {

Console.log ("Before Mount")

Console.log (THIS.A)

Console.log (this. $el)

},

Mounted:function () {

Console.log ("after Mount")

Console.log (THIS.A)

Console.log (this. $el)

},

Beforeupdate:function () {

Console.log ("Pre-update");

Console.log (THIS.A)

Console.log (this. $el)

},

Updated:function () {

Console.log ("Update Complete");

Console.log (THIS.A);

Console.log (this. $el)

},

Beforedestroy:function () {

Console.log ("Prior to destruction");

Console.log (THIS.A)

Console.log (this. $el)

Console.log (this. $el)

},

Destroyed:function () {

Console.log ("destroyed");

Console.log (THIS.A)

Console.log (this. $el)

}

});

</script>

After running, view the console,

Get this:


Then add a change method to the methods:

<div Id=app>{{a}}
<button v-on:click= "Change" >change</button>
</div>

When you click the button, it appears:

This is the life cycle of vue, very simple.

The life cycle of Vue JS (read it)

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.