Feat: 增加按钮并且修改路由,实现页面跳转

This commit is contained in:
2025-12-19 17:15:41 +08:00
parent a5d7c70ce5
commit c08e628b38
3 changed files with 53 additions and 1 deletions
+22
View File
@@ -12,6 +12,28 @@ struct Index {
.onClick(() => { .onClick(() => {
this.message = 'Welcome'; this.message = 'Welcome';
}) })
Button() {
Text('Next')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
.onClick(() => {
console.log("用户操作:点击按钮")
let uiContext: UIContext = this.getUIContext();
let router = uiContext.getRouter();
router.pushUrl({
url: 'pages/Second'
}).then(() => {
console.log('系统提示:跳转成功')
})
})
} }
.width('100%') .width('100%')
} }
+29
View File
@@ -0,0 +1,29 @@
@Entry
@Component
struct Second {
@State message: string = '万物互联';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('Back')
.fontSize(30)
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('40%')
.height('5%')
}
.width('100%')
}
.height('100%')
}
}
@@ -1,5 +1,6 @@
{ {
"src": [ "src": [
"pages/Index" "pages/Index",
"pages/Second"
] ]
} }