当前位置: 首页 > 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>
http://www.dtcms.com/a/56629.html

相关文章:

  • 物联网智慧农业一体化解决方案-可继续扩展更多使用场景
  • 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 实时时钟适配移植
  • QTday4
  • 谈谈你对 Seata 的理解?
  • 第四章:go 不同进制的区分 for _, r :=range 使用
  • 【入门级篇】保姆级教程:零基础实现DeepSeek本地部署的两种终极方案(附避坑指南)
  • 红果短剧安卓+IOS双端源码,专业短剧开发公司
  • vLLM + Open-WebUI 本地私有化部署 DeepSeek-R1-Distill-Qwen-32B 方案
  • 如火如荼的deepseek,AI初试探!
  • 如何基于LLM及NL2SQL打造对话式智能BI助手
  • 网络与网络安全
  • Springboot-mybatis配置多数据源