@Entry 装饰的页面,A 页面跳到 B 页面后再跳回 A 页面,如何获取 B 页面的返回值

router.back({
  url: 'pages/Home',
  params: {
    info: '来自Home页'
  }
})

// 这些参数可以在目标页面中
// 通过调用 router.getParams() 方法进行获取
 onPageShow() {
    const params = router.getParams() as Record<string, string>
    console.log(params)
  }

// AdPage.ets import router from '@ohos.router'; import image from '@ohos.multimedia.image'; @Entry @Component struct AdPage { @State count: number = 5 private timerId: number | null = null private currentIndex: number = 0 // 广告数据 private adList: AdItem[] = [ { id: 1, image: $r('app.media.gg1'), target: 'pages/DetailPage?adId=1' }, { id: 2, image: $r('app.media.gg2'), target: 'pages/DetailPage?adId=2' }, { id: 3, image: $r('app.media.gg3'), target: 'pages/DetailPage?adId=3' }, { id: 4, image: $r('app.media.gg4'), target: 'pages/DetailPage?adId=4' }, { id: 5, image: $r('app.media.gg5'), target: 'pages/DetailPage?adId=5' } ] // 页面显示启动倒计时 onPageShow() { this.startTimer() } // 页面隐藏清除资源 onPageHide() { this.clearTimer() } // 启动倒计时 private startTimer() { this.timerId = setInterval(() => { this.count = this.count - 1 if (this.count <= 0) { this.jumpToHome() } }, 1000) } // 清除定时器 private clearTimer() { if (this.timerId) { clearInterval(this.timerId) this.timerId = null } } // 转首页 private jumpToHome() { this.clearTimer() router.replaceUrl({ url: 'pages/HomePage' }) } // 广告点击处理 private onAdClick(target: string) { this.clearTimer() router.pushUrl({ url: target }) } // 轮播切换事件 private onSwiperChange(index: number) { this.currentIndex = index } build() { Stack({ alignContent: Alignment.TopEnd }) { // 广告轮播 Swiper({ index: this.currentIndex, loop: true }) { ForEach(this.adList, (item: AdItem) => { Image(item.image) .width('100%') .height('100%') .objectFit(ImageFit.Cover) .onClick(() => this.onAdClick(item.target)) }, item => item.id.toString()) } .indicator(true) .autoPlay(true) .interval(3000) .onChange((index: number) => this.onSwiperChange(index)) .width('100%') .height('100%') // 过按钮 Button(`过 ${this.count}s`, { type: ButtonType.Capsule }) .width(90) .height(40) .fontColor(Color.White) .backgroundColor('#66000000') .margin({ top: 30, right: 20 }) .onClick(() => this.jumpToHome()) } } } // 广告项类型定义 class AdItem { id: number = 0 image: Resource = $r('app.media.default_ad') target: string = '' } 这是代码> hvigor ERROR: Failed :entry:default@PreviewArkTS... > hvigor ERROR: ArkTS:ERROR File: D:/huawi/createproject/entry/src/main/ets/pages/shishishi.ets:76:12 Use explicit types instead of "any", "unknown" (arkts-no-any-unknown) ArkTS:ERROR File: D:/huawi/createproject/entry/src/main/ets/pages/shishishi.ets:69:16 Argument of type '{ index: number; loop: boolean; }' is not assignable to parameter of type 'SwiperController'. Object literal may only specify known properties, and 'index' does not exist in type 'SwiperController'. ArkTS:ERROR File: D:/huawi/createproject/entry/src/main/ets/pages/gg.ets:5:8 struct 'Myd' must be at least or at most one 'build' method. * Try the following: > A structurally modified page must have at least one and no more than one'build' method.ArkTS:ERROR File: D:/huawi/createproject/entry/src/main/ets/pages/shishishi.ets:100:24 Unknown resource name 'default_ad'. > hvigor ERROR: BUILD FAILED in 53 s 426 ms 这是错误修改代码
10-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值