跳转按钮代码:
// 跳转按钮:跳转到详情页
Button('跳转到详情页34')
.fontSize(18)
.width(200)
.height(50)
.backgroundColor('#007DFF')
.onClick(() => {
// 调用Router.pushUrl实现跳转
router.pushUrl({
url: 'pages/router/detail', // 目标页面路径(与main_pages.json中一致)
params: {
// 传递参数(可选)
name: this.userName,
age: this.userAge,
isStudent: false
}
}).then(() => {
console.log('跳转成功')
}).catch((err:Error) => {
console.log('跳转失败:' + err.message)
})
})
且需要在
main_pages.json
配置

如果需要网络请求,
则需要

写一个
"requestPermissions": [
{ "name": "ohos.permission.INTERNET" } // 允许网络请求
],