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一蓑烟雨任平生3 天前
Vue3 表单输入绑定
vue.js·vue3·v-model·vue3 表单输入绑定·表单输入绑定·input和change区别·vue3 双向数据绑定
麦麦大数据4 天前
D026 vue3+django 论文知识图谱推荐可视化系统 | vue3+vite前端|neo4j 图数据库
前端·django·vue3·知识图谱·推荐算法·论文文献·科研图谱
duansamve4 天前
Vue3和vue2的Diff算法有何差异?
vue·vue3·vue2·diff
JNU freshman5 天前
Element Plus组件
前端·vue.js·vue3
Sheldon一蓑烟雨任平生8 天前
Vue3 列表渲染
vue.js·vue3·v-for·列表渲染·vue3 列表渲染·v-for 循环对象·v-for与计算属性
duansamve8 天前
TS在Vue3中的使用实例集合
typescript·vue3
ღ᭄ꦿ࿐Never say never꧂8 天前
微信小程序 Button 组件 open-type 完全指南:从用户信息获取到客服分享的实战应用
spring boot·微信小程序·小程序·uni-app·vue3
Sheldon一蓑烟雨任平生9 天前
Vue3 Class 与 Style 绑定
vue.js·vue3·class与style绑定·绑定class·绑定style·vue3绑定class·vue3绑定style
alwaysrun17 天前
Rust中所有权和作用域及生命周期
rust·生命周期·作用域·所有权·引用与借用
昔冰_G18 天前
Vue内置组件KeepAlive——缓存组件实例
vue.js·缓存·vue3·vue2·keep-alive·vue组件缓存·vue内置组件