vue3 生命周期

与 2.x 版本生命周期相对应的组合式 API

beforeCreate -> 使用 setup()
created -> 使用 setup()
beforeMount -> onBeforeMount
mounted -> onMounted
beforeUpdate -> onBeforeUpdate
updated -> onUpdated
beforeDestroy -> onBeforeUnmount
destroyed -> onUnmounted
errorCaptured -> onErrorCaptured

使用

	import {
   onBeforeMount,onMounted } from 'vue'
	
	//在组件被挂载之前调用
	onBeforeMount(()=>{
   
	   console.log('组件被挂载之前')
	})
	//在组件被挂载之后调用
	onMounted(() => {
   
	   console.log('在组件被挂载之后')
	});
	

在这里插入图片描述

相关推荐

  1. vue3生命周期

    2024-01-13 03:22:02       25 阅读
  2. Vue3生命周期Vue2生命周期对比

    2024-01-13 03:22:02       60 阅读
  3. Vue3生命周期 VS Vue2生命周期(小记)

    2024-01-13 03:22:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-13 03:22:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-13 03:22:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-13 03:22:02       82 阅读
  4. Python语言-面向对象

    2024-01-13 03:22:02       91 阅读

热门阅读

  1. CycleGAN(Cycle-Consistent Generative Adversarial Network)

    2024-01-13 03:22:02       44 阅读
  2. 【linux】利用echo命令实现不换行的倒计时

    2024-01-13 03:22:02       54 阅读
  3. [树莓派]给树莓派装pyinstaller环境

    2024-01-13 03:22:02       60 阅读
  4. Pandas实战100例 | 案例 9: 数据重塑 - `pivot` 和 `melt`

    2024-01-13 03:22:02       49 阅读
  5. SQL server 给列添加描述

    2024-01-13 03:22:02       68 阅读
  6. 图像处理中常用的距离

    2024-01-13 03:22:02       55 阅读