Feat: 增加按钮并且修改路由,实现页面跳转
This commit is contained in:
@@ -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%')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user