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

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.kler.cn/a/574226.html

相关文章:

  • MyBatis-Plus开发流程:Spring Boot + MyBatis-Plus 实现对 book_tab 表的增删改查及Redis缓存
  • Tomcat 新手入门指南
  • AI技术赋能增长,新一代呼叫中心系统,完美适配企业转型
  • Spring WebFlux 中 WebSocket 使用 DataBuffer 的注意事项
  • ORACLE导入导出
  • 搭建一个跳板服务器的全过程
  • TP-LINK图像处理工程师(深圳)内推
  • 质量属性场景描述
  • 计算机视觉算法实战——表面缺陷检测(表面缺陷检测)
  • XGBClassifiler函数介绍
  • 【mysql系】mysql启动异常Can‘t create test file localhost.lower-test
  • 力扣经典题目:接雨水
  • 使用python进行数据分析需要安装的库
  • MyBatis 配置文件核心
  • 【HeadFirst系列之HeadFirst设计模式】第16天之生成器模式(Builder Pattern):让对象构建更优雅!
  • 传统工厂转型实录:1套WMS系统如何砍掉40%仓储成本
  • 深入Sentinel使用和源码分析
  • uniapp登录用户名在其他页面都能响应
  • 【FFmpeg之如何新增一个硬件解码器】
  • 华为OD机试-发现新词的数量(Java 2024 E卷 100分)