<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>理解Vue中的生命周期函数</title>
<script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="root"></div>
</body>
<script>
// 生命周期函数: 在某一时刻会自动执行的函数
const app = Vue.createApp({
data() {
return {
message: 'hello world'
}
},
// 在实例生成之前会自动执行的函数
beforeCreate() {
console.log('beforeCreate')
},
// 在实例生成之后会自动生成的函数
created() {
console.log('created')
},
// 在模版已经变成函数之后立即自动执行的函数
// 或理解为 在组件内容被渲染到页面之前立即自动执行的函数
beforeMount() {
console.log('beforeMount')
},
// 在组件内容被渲染到页面之后自动执行的函数
mounted() {
console.log('mounted')
},
// 当数据发生变化时会自动执行的函数
beforeUpdate() {
console.log('beforeUpdate')
},
// 当数据发生变化,页面重新渲染后,会自动执行的函数
updated() {
console.log('updated')
},
// 当 Vue 实例销毁时会自动执行的函数
beforeUnmount() {
console.log('beforeUnmount')
},
// 当Vue 应用失效时,且DOM完全销毁之后,自动执行的函数
unmounted() {
console.log('unmounted')
},
template: "<div>{{message}}</div>"
});
const vm = app.mount('#root');
</script>
</html>
Vue实例生命周期以及图示
原创xyphf_和派孔明 博主文章分类:vue.js入门 ©著作权
文章标签 vue.js javascript elementui html 生命周期 文章分类 JavaScript 前端开发
©著作权归作者所有:来自51CTO博客作者xyphf_和派孔明的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:Vue实例
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
vue-生命周期图示 注解
vue生命周期图示 注解
vue 学习笔记 生命周期 官网 数据 -
vue实例生命周期do better myself
-
vue3 生命周期(生命周期钩子 vs 生命周期选项 vs 缓存实例的生命周期)
vue3 支持两种风格书写:选项式 API 和组合式 API。
vue.js 缓存 服务器端 生命周期 -
vue实例的生命周期【重要】
前言js的表达式,对象的简写就是属性和属性值相同,简写可以只写一个。js很多时候难以识别小数,因此我们需要
vue.js 前端 生命周期 图例 死循环