Vue.js 的生命周期指的是 Vue 实例从创建到销毁的整个过程,它包括了一系列的阶段和钩子函数,允许开发者在不同的阶段执行自定义逻辑。以下是 Vue.js 生命周期的概述:
this
指向新创建的 Vue 实例。new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
},
beforeCreate: function () {
console.log('beforeCreate');
console.log(this); // 此时 this 指向 Vue 实例
},
created: function () {
console.log('created');
console.log(this.message); // 此时可以访问 data 中的值
},
beforeMount: function () {
console.log('beforeMount');
},
mounted: function () {
console.log('mounted');
},
beforeUpdate: function () {
console.log('beforeUpdate');
},
updated: function () {
console.log('updated');
},
beforeDestroy: function () {
console.log('beforeDestroy');
},
destroyed: function () {
console.log('destroyed');
}
});
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。