Vue生命周期

{{ message }}
var app = new Vue({ el: '#app', data: { message: 'Hello Vue!' }, beforeCreate: function() { console.log('--------------beforeCreate----------------'); console.log(this.$el); console.log('data: ' + this.$data); console.log('message: ' + this.message); }, created: function() { console.log('--------------created----------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, beforeMount: function() { console.log('--------------beforeMount-----------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, mounted: function() { console.log('--------------mounted---------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, beforeUpdate: function() { console.log('--------------beforeUpdate----------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, updated: function() { console.log('--------------updated---------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, beforeDestroy: function() { console.log('--------------beforeDestroy---------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); }, destroyed: function() { console.log('--------------destroyed-------------'); console.log(this.$el); console.log('data: ' + JSON.stringify(this.$data)); console.log('message: ' + this.message); } })
Vue生命周期_第1张图片
demo.png

Vue生命周期_第2张图片
update.png

Vue生命周期_第3张图片
destroy.png

Vue生命周期_第4张图片
lifecycle.png
beforeCreate created beforeMount mounted beforeUpdate updated beforeDestroy destroyed
data observer & event/watcher 事件配置之前 data observer & event/watcher 完成,$el不可见 $el可见,挂载之前 挂载完成 数据更新,DOM未渲染 DOM已渲染 实例销毁前,实例仍可用 解绑完成

你可能感兴趣的:(Vue生命周期)