生命周期函数
import router from '@ohos.router'
@Entry
@Component
struct Index {
// 页面的生命周期 -- 5个 (如果是组件,则只有前2个;如果是页面则有5个)
// 组件有的2个
aboutToAppear() {
console.log('aboutToAppear --- 将要出现')
}
aboutToDisappear() {
console.log('aboutToAppear --- 即将销毁')
}
// 页面新增的3个
onPageShow() {
console.log('onPageShow --- 页面显示')
}
onPageHide() {
console.log('onPageHide --- 页面隐藏')
}
onBackPress() {
console.log('onBackPress --- 当用户点击返回按钮时触发')
}
build() {
Column({ space: 10 }) {
Text('首页').fontSize(30)
Button('去详情页').onClick((event: ClickEvent) => {
router.pushUrl({ url: 'pages/demo03/life_cycle/Detail' })
})
}.width('100%')
.padding(10)
}
}
标签:生命周期,console,log,aboutToAppear,基础,---,HarmonyOS,router,页面
From: https://www.cnblogs.com/ybbit/p/18133527