vue3 生命周期

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

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

使用

javascript 复制代码
	import {onBeforeMount,onMounted } from 'vue'
	
	//在组件被挂载之前调用
	onBeforeMount(()=>{
	   console.log('组件被挂载之前')
	})
	//在组件被挂载之后调用
	onMounted(() => {
	   console.log('在组件被挂载之后')
	});
	
相关推荐
Sheldon一蓑烟雨任平生1 天前
Sass 星空(Sass + keyframes 实现星空动画)
前端·css·vue3·sass·keyframes
Irene19912 天前
Vue 3 中移除了 $on、$off 和 $once 方法(附:Composables 组合式函数 使用详解)
vue3
Sapphire~3 天前
Vue3-15 html标签和组件上的ref属性 + 接口泛型
vue3
Irene19913 天前
Vue 3 中使用 Mitt 事件总线
vue3·mitt
咸甜适中3 天前
双色球、大乐透兑奖分析小程序(rust_Tauri + Vue3 + sqlite)
爬虫·rust·sqlite·vue3·tauri2
Sapphire~5 天前
Vue3-012 vue2与vue3中的computed
vue3
Sapphire~8 天前
Vue3-11 toRefs 和 toRef
vue3
华玥作者9 天前
uni-app + Vite 项目中使用 @uni-helper/vite-plugin-uni-pages 实现自动路由配置(超详细)
前端·uni-app·vue·vue3·vite
ttod_qzstudio10 天前
把“行为”做成乐高——Babylon.js Behavior 开发套路
生命周期·behavior·babylon.js·内存安全·非空断言
独立开发者阿乐10 天前
Vue3中Markdown解析与渲染的完整解决方案:从安全到性能优化
web安全·性能优化·vue3·前端开发·语法高亮·markdown解析·markdown-it