.fontWeight(FontWeight.Bold)
Button('跳转1')
.width(100)
.margin({ top: 10 })
.onClick(() => {
router.pushUrl({ url: 'pages/HomePage', params: { msg: 'hello world,我是上一个页面传递过来的' } },
router.RouterMode.Standard, (err) => {
if (err) {
promptAction.showToast({ message: 跳转失败:code is ${err.code}, message is ${err.message} })
return;
} else {
promptAction.showToast({ message: 跳转成功 })
}
} )
})
Button('跳转2')
.width(100)
.margin({ top: 10 })
.onClick(() => {
router.pushUrl({ url: 'pages/HomePage' },
router.RouterMode.Single, (err) => {
if (err) {
promptAction.showToast({ message: 跳转失败:code is ${err.code}, message is ${err.message} })
return;
} else {
promptAction.showToast({ message: 跳转成功 })
}
} )
})
Button('跳转3')
.width(100)
.margin({ top: 10 })
.onClick(() => {
router.replaceUrl({ url: 'pages/HomePage' },
router.RouterMode.Single, (err) => {
if (err) {
promptAction.showToast({ message: 跳转失败:code is ${err.code}, message is ${err.message} })
return;
} else {
promptAction.showToast({ message: 跳转成功 })
}
} ) })
} .width('100%') } .height('100%') } }
HomePage.ets
import router from '@ohos.router'; import promptAction from '@ohos.promptAction';
@Entry @Component struct HomePage { @State message: string = 'HomePage' @State msg: string = '';
onPageShow() { // 获取传递过来的参数对象 const params = router.getParams(); if (params != null && this.msg != null) { // 获取info属性的值 this.msg = params['msg']; } else { this.msg = '没有参数传递过来' } }
build() { Row() { Column() {
Text(this.msg) .fontSize(20)
Button('返回上一页').onClick(() => { router.back() })
Button('返回指定页面') .margin({ top: 10 }) .onClick(() => { router.back({ url: 'pages/Index' }) })
Button('页面返回询问框') .margin({ top: 10 }) .onClick(() => {
// 调用router.showAlertBeforeBackPage()方法,设置返回询问框的信息
try {
router.showAlertBeforeBackPage({
message: '您还没有完成支付,确定要返回吗?' // 设置询问框的内容
});
} catch (err) {
console.error(Invoke showAlertBeforeBackPage failed, code is ${err.code}, message is ${err.message});
}
router.back()
})
Button('页面返回询问框自定义') .margin({ top: 10 }) .onClick(() => {
// 弹出自定义的询问框
promptAction.showDialog({
message: '您还没有完成支付,确定要返回吗?',
buttons: [
{
text: '取消',
color: '#FF0000'
},
{
text: '确认',
color: '#0099FF'
}
]
}).then((result) => {
if (result.index === 0) {
// 用户点击了“取消”按钮
console.info('User canceled the operation.');
} else if (result.index === 1) {
// 用户点击了“确认”按钮
console.info('User confirmed the operation.');
// 调用router.back()方法,返回上一个页面
router.back();
}
}).catch((err) => {
console.error(Invoke showDialog failed, code is ${err.code}, message is ${err.message});
})
})
} .width('100%') } .height('100%') } }
为了能让大家更好的学习鸿蒙 (OpenHarmony) 开发技术,这边特意整理了《鸿蒙 (OpenHarmony)开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05
《鸿蒙 (OpenHarmony)开发学习手册》:https://qr21.cn/FV7h05
入门必看:https://qr21.cn/FV7h05
1. 应用开发导读(ArkTS)
2. ……
HarmonyOS 概念:https://qr21.cn/FV7h05
- 系统定义
- 技术架构
- 技术特性
- 系统安全
如何快速入门:https://qr21.cn/FV7h05
1. 基本概念
2. 构建第一个ArkTS应用
3. 构建第一个JS应用
4. ……
开发基础知识:https://qr21.cn/FV7h05
1. 应用基础知识
2. 配置文件
3. 应用数据管理
4. 应用安全管理
5. 应用隐私保护
6. 三方应用调用管控机制
7. 资源分类与访问
8. 学习ArkTS语言
9. ……
基于ArkTS 开发:https://qr21.cn/FV7h05
1. Ability开发
2. UI开发
3. 公共事件与通知
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新