当前位置: 首页 > news >正文

Vue2 的生命周期有哪些

一、生命周期与钩子函数

Vue的生命周期可以大致分为三个阶段:初始化组件实例阶段、更新组件实例阶段和销毁组件实例阶段。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<template>
  <div>
    <p>{{ message }}</p>
    <button @click="updateMessage">Update Message</button>
    <button @click="destroyComponent">Destroy Component</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      message: 'Hello Vue!'
    };
  },
  beforeCreate() {
    console.log('beforeCreate');
  },
  created() {
    console.log('created');
  },
  beforeMount() {
    console.log('beforeMount');
  },
  mounted() {
    console.log('mounted');
  },
  beforeUpdate() {
    console.log('beforeUpdate');
  },
  updated() {
    console.log('updated');
  },
  beforeDestroy() {
    console.log('beforeDestroy');
  },
  destroyed() {
    console.log('destroyed');
  },
  methods: {
    updateMessage() {
      this.message = 'Updated Message!';
    },
    destroyComponent() {
      this.$destroy(); // 手动销毁组件
    }
  }
};
</script>

相关文章:

  • 物联网智慧农业一体化解决方案-可继续扩展更多使用场景
  • SpringBoot整合Caffeine本地缓存
  • Server-Sent Events
  • 正则表达式(2)匹配规则
  • SQL注入练习场:PHPStudy+SQLI-LABS靶场搭建教程(零基础友好版)
  • 【Find My功能科普】防盗黑科技如何改变生活?
  • 提升大模型Text-to-SQL能力应用的实践
  • 人工智能与深度学习的应用案例:从技术原理到实践创新
  • VBA之Word应用第三章第七节:文档Document对象的方法(一)
  • 高效编程指南:PyCharm与DeepSeek的完美结合
  • 2.Swift Tabbar的使用
  • 软考中级_【软件设计师】知识点之【数据库】
  • Llama-Factory框架下的Meta-Llama-3-8B-Instruct模型微调
  • CentOS 最新系统安装 Redis 7.0.11 详细指南
  • 重生之数据结构与算法----数组链表
  • 2025-03-06 学习记录--C/C++-PTA 练习8-8 移动字母
  • Android MXPlayer-v1.86.0-wushidi专业版[原团队最后一个版本]
  • 实战案例分享:Android WLAN Hal层移植(MTK+QCA6696)
  • 编程语言介绍:Rust
  • RK3588V2--HYM8563TS RTC 实时时钟适配移植
  • 做导购网站多少钱/企业管理软件排名
  • 网站备案信息保护/网页搭建
  • 网站制作app/seo工作内容
  • 深圳网站建设费用大概/有没有专门做营销的公司
  • 百度seo收录/只要做好关键词优化
  • 天津免费网站建站模板/友链网站