鸿蒙开发之初页面UIAbility
UIAbility 类似于一个整体的应用声明入口, 比如小程序的app.js , 比如安卓端的activity
正常页面开发 使用的是一个UIAbility即可, 然后在一个UIAbility 里面 通过路由的形式进行跳转

关于路由
导入
import router from '@ohos.router';
跳转
router.pushUrl({
url: 'pages/Second',
params: {
src: 'Index页面传来的数据',
}
}, router.RouterMode.Single)
接受参数
import router from '@ohos.router';
@Entry
@Component
struct Second {
@State src: string = (router.getParams() as Record<string, string>)['src'];
// 页面刷新展示
// ...
}
其他API
//返回 router.back(); //待补充
那么, 在整体的应用框架上的声明周期 ,最主要的是
onWindowStageCreate
这个方法, 定义了入口page
onWindowStageCreate(windowStage: window.WindowStage) {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
//入口文件是pages/Index
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
其他方式 请查看具体文档https://developer.huawei.com/consumer/cn/training/course/slightMooc/C101682410084699146
浙公网安备 33010602011771号