当前位置:   article > 正文

HarmonyOS开发DecEco Studio页面跳转_deveco studio怎么从一个ets跳转到另一个ets

deveco studio怎么从一个ets跳转到另一个ets

一、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%')
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

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%')
  }
}```

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/36688?site
推荐阅读
相关标签
  

闽ICP备14008679号