VDone Demo VDone Demo
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)

Nikolay Tuzov

Backend Developer
Home
  • Articles

    • JavaScript
  • Study Notes

    • JavaScript Tutorial
    • Professional JavaScript
    • ES6 Tutorial
    • Vue
    • React
    • TypeScript: Build Axios from Scratch
    • Git
    • TypeScript
    • JS Design Patterns
  • HTML
  • CSS
  • Technical Docs
  • GitHub Tips
  • Node.js
  • Blog Setup
  • Learning
  • Interviews
  • Miscellaneous
  • Practical Tips
  • Friends
About
Bookmarks
  • Categories
  • Tags
  • Archives
GitHub (opens new window)
  • 基础

    • MVVM Pattern
    • Lifecycle
      • Demo
      • Lifecycle Diagram
    • Computed Properties vs Methods vs Watchers
    • v-if vs v-show
    • List Rendering - Array and Object Change Detection
  • 组件

  • 过渡&动画

  • 可复用性&组合

  • 工具

  • 规模化

  • Vuex

  • 其他

  • 《Vue》笔记
  • 基础
xugaoyi
2020-02-04
Contents

Lifecycle

# Instance Lifecycle Hooks

Instance Lifecycle Hooks API (opens new window)

Simply put, lifecycle hook functions are functions that a Vue instance automatically executes at certain points in time.

<div id="app">{{msg}}</div>

<script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
<script>
  var vm = new Vue({
    el: '#app',
    data: {
      msg: 'Vue Lifecycle'
    },
    beforeCreate: function() {
      console.group('------beforeCreate state------');
      console.log("el     : " + this.$el); //undefined
      console.log("data   : " + this.$data); //undefined
      console.log("msg: " + this.msg) //undefined
    },
    created: function() {
      console.group('------created state------');
      console.log("el     : " + this.$el); //undefined
      console.log("data   : " + this.$data); //initialized
      console.log("msg: " + this.msg); //initialized
    },
    beforeMount: function() {
      console.group('------beforeMount state------');
      console.log(this.$el);// <div id="app">{{msg}}</div> before mount state
    },
    mounted: function() {
      console.group('------mounted state------');
      console.log(this.$el);// <div id="app">Vue Lifecycle</div>   msg content is mounted and rendered to the page
    },
      // Before data is modified
    beforeUpdate: function () {
      console.group('beforeUpdate state===============>');
      console.log("el     : " + this.$el);
      console.log(this.$el);
      console.log("data   : " + this.$data);
      console.log("msg: " + this.msg);
    },
      // After beforeUpdate is triggered, the virtual DOM re-renders and applies updates
      // After data is modified
    updated: function () {
      console.group('updated state===============>');
      console.log("el     : " + this.$el);
      console.log(this.$el);
      console.log("data   : " + this.$data);
      console.log("msg: " + this.msg);
    },
      // Before calling vm.$destroy()
    beforeDestroy: function () {
      console.group('beforeDestroy state===============>');
      console.log("el     : " + this.$el);
      console.log(this.$el);
      console.log("data   : " + this.$data);
      console.log("msg: " + this.msg);
    },
       // After calling vm.$destroy()
    destroyed: function () {
      console.group('destroyed state===============>');
      console.log("el     : " + this.$el);
      console.log(this.$el);
      console.log("data   : " + this.$data);
      console.log("msg: " + this.msg)
    }
  })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

# Demo

See the Pen 生命周期钩子 by xugaoyi (@xugaoyi) on CodePen.

# Lifecycle Diagram

Edit (opens new window)
#Vue
Last Updated: 2026/03/21, 12:14:36
MVVM Pattern
Computed Properties vs Methods vs Watchers

← MVVM Pattern Computed Properties vs Methods vs Watchers→

Recent Updates
01
How I Discovered Disposable Email — A True Story
06-12
02
Animations in Grid Layout
09-15
03
Renaming a Git Branch
08-11
More Articles >
Theme by VDone | Copyright © 2026-2026 Nikolay Tuzov | MIT License | Telegram
  • Auto
  • Light Mode
  • Dark Mode
  • Reading Mode