<script>
// 引入生命周期函数时,在之前基础上加上on
import { onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted } from 'vue'
export default {
setup () {
// beforeCreate、created 这两个不是引入方式
onBeforeMount(() => {
console.log( 'beforeMount:组件被挂载前调用');
})
onMounted(() => {
console.log('mounted:组件被挂载之后调用');
})
onBeforeUpdate(() => {
console.log('beforeUpdate:更新DOM树前调用');
})
onUpdated(() => {
console.log('updated:更新DOM树后调用');
})
onBeforeUnmount(() => {
console.log('beforeUnmount:实例被卸载前调用');
})
onUnmounted(() => {
console.log('unmounted:实例被卸载后调用');
})
},
beforeCreate () {
console.log('组件中使用beforeCreate:数据初始化之前');
},
created () {
console.log('组件中使用created:数字初始化之后');
},
}
</script>
Vue——vue3中setup() 组件中引入生命周期函数写法
最新推荐文章于 2024-07-22 17:01:36 发布