华为 HarmonyOS开发DecEco Studio页面跳转 - router’

📅 2026-11-30 👤 拼多多助力营销技巧 📂 pdd帮助力 👁️ 143 次阅读

一、pages创建新页面 在index.ets增加路由: import router from ‘@ohos.router’; //页面路由跳转

import router from '@ohos.router';

let msg:string='Index 页面传来的数据'; //数据

@Entry

@Component

struct Index {

@State message: string = 'Hello World'

build() { 拼多多帮助力入口

Row() {

Column() {

Text(this.message)

.fontSize(50)

.fontWeight(FontWeight.Bold)

Button('Exit')

.width('80%').height(40)

.onClick(()=>{

router.push({

url:'pages/Second',

params:{ //在router.push方法时传递src数据

src:msg,

}

});

})

}

.width('100%').height(140)

}

.height('100%')

}

}

router.push()执行跳转 url:‘pages/Second’, //页面途径 params:{ src:msg, //传递数据 }

import router from '@ohos.router';

@Entry

@Component

struct Second {

@State message: string = 'Hello World'

@State src:string = router.getParams()?.['src']; //获取传递的数据

build() {

Row() {

Column() {

Text(this.message) //创建字体

.fontSize(50)

.fontWeight(FontWeight.Bold)

Text(this.src) //创建字体 展示传递的数据

.fontSize(20)

.fontColor(Color.Red) //字体颜色

}

.width('100%')

}

.height('100%')

}

}```

参考文章

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧