// Vue 生命周期示例代码
new Vue({
el: '#app',
data() {
return {
message: 'Hello Vue!'
}
},
beforeCreate() {
console.log('beforeCreate: 实例初始化完毕,数据观测 (data observer) 和 event/watcher 事件配置尚未初始化。');
},
created() {
console.log('created: 完成数据观测 (data observer),属性和方法的运算,watch/event 事件回调。');
},
beforeMount() {
console.log('beforeMount: 模板编译/挂载之前,虚拟 DOM 首次被渲染。');
},
mounted() {
console.log('mounted: 模板编译/挂载之后,虚拟 DOM 被渲染到页面上。');
},
beforeUpdate() {
console.log('beforeUpdate: 数据更新时调用,发生在虚拟 DOM 打补丁之前。');
},
updated() {
console.log('updated: 数据更新后,虚拟 DOM 重新渲染和打补丁之后调用。');
},
beforeDestroy() {
console.log('beforeDestroy: 实例销毁之前调用。在这一步,实例仍然完全可用。');
},
destroyed() {
console.log('destroyed: 实例销毁后调用。调用后,所有的事件监听器会被移除,所有的子实例也会被销毁。');
}
});
render
函数首次被调用。通过这些生命周期钩子函数,开发者可以在不同的阶段执行特定的操作,例如初始化数据、获取外部资源、清理定时器等。
上一篇:vue3 ref
下一篇:vue3.0
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站