HarmonyOS Refresh组件下拉刷新ui无刷新,debug过list是有数据的

@Entry
@Component
struct TestPage {
  @State isRefreshing: boolean = false
  commentsList: CommentList[] = []

  build() {
    Refresh({ refreshing: $$this.isRefreshing, builder: this.customRefreshComponent() }) {
      List() {
        ForEach(this.commentsList, (item: CommentList, index: number) => {
          ListItem() {
            Row() {
              Image($r('app.media.head'))
                .alt($r('app.media.head'))
                .height(20).width(20)
                .margin(8)
              Text() {
                Span(item.name + ':')
                  .fontColor($r('app.color.AAAAAA'))
                  .fontSize('14fp')
                Span(item.content)
                  .fontColor($r('app.color.333333'))
                  .fontSize('14fp')
              }
              .margin({ top: 10, bottom: 10, right: 12 })

            }
            .margin({
              top: 5,
              bottom: 5,
              left: 20,
              right: 20
            })
            .borderRadius(4)
            .backgroundColor($r('app.color.F5F5F5'))
          }
        })
      }
      .scrollBar(BarState.Off)
      .width('100%')
      .height('100%')
      .margin({ top: 50 })
    }
    .onRefreshing(() => {
      this.commentsList.push(new CommentList('111', 'xxx'))
      this.isRefreshing = false
    })
  }

  aboutToAppear(): void {

    this.commentsList.push(new CommentList('111', 'xxx'))
    this.commentsList.push(new CommentList('222', 'xxx'))
    this.commentsList.push(new CommentList('333',
      'xxx'))
    this.commentsList.push(new CommentList('555',
      'xxx'))
  }

  @Builder
  customRefreshComponent() {
    Stack() {
      Row() {
        LoadingProgress().height(32)
        Text("刷新中").fontSize(16).margin({ left: 20 })
      }
      .alignItems(VerticalAlign.Center)
    }.width("100%").align(Alignment.Center)
  }
}

@Observed
export class CommentList {
  name: string
  content: string

  constructor(name: string, content: string) {
    this.name = name
    this.content = content
  }
}
  • 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.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
HarmonyOS
2024-12-25 12:46:25
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

改成用@State装饰器去定义数据,具体改动如下:

@Entry
@Component
struct TestPage {
  @State isRefreshing: boolean = false
  @State commentsList: CommentList[] = []

  build() {
    Refresh({ refreshing: $$this.isRefreshing, builder: this.customRefreshComponent() }) {
      List() {
        ForEach(this.commentsList, (item: CommentList, index: number) => {
          ListItem() {
            Row() {
              Image($r('app.media.background'))
                .alt($r('app.media.foreground'))
                .height(20).width(20)
                .margin(8)
              Text() {
                Span(item.name + ':')
                  .fontColor(Color.Black)
                  .fontSize('14fp')
                Span(item.content)
                  .fontColor(Color.Brown)
                  .fontSize('14fp')
              }
              .margin({ top: 10, bottom: 10, right: 12 })

            }
            .margin({
              top: 5,
              bottom: 5,
              left: 20,
              right: 20
            })
            .borderRadius(4)
            .backgroundColor(Color.Pink)
          }
        })
      }
      .scrollBar(BarState.Off)
      .width('100%')
      .height('100%')
      .margin({ top: 50 })
    }
    .onRefreshing(() => {
      this.commentsList = [...this.commentsList, new CommentList('111', 'ArkTS提供了简洁自然的声明式语法')]
      this.isRefreshing = false
    })
  }

  aboutToAppear(): void {
    this.commentsList.push(new CommentList('111', 'xxx'))
    this.commentsList.push(new CommentList('222', 'xxx'))
    this.commentsList.push(new CommentList('333',
      'xxx'))
    this.commentsList.push(new CommentList('555',
      'xxx'))
  }

  @Builder
  customRefreshComponent() {
    Stack() {
      Row() {
        LoadingProgress().height(32)
        Text("刷新中").fontSize(16).margin({ left: 20 })
      }
      .alignItems(VerticalAlign.Center)
    }.width("100%").align(Alignment.Center)
  }
}

@Observed
export class CommentList {
  name: string
  content: string

  constructor(name: string, content: string) {
    this.name = name
    this.content = content
  }
}
  • 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.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
分享
微博
QQ
微信
回复
2024-12-25 16:24:24
相关问题
HarmonyOS使用Refresh下拉刷新问题
1534浏览 • 1回复 待解决
HarmonyOS LIst组件UI刷新
586浏览 • 1回复 待解决
Refresh结合lottie实现下拉刷新动画
1900浏览 • 1回复 待解决
HarmonyOS 组件下拉刷新问题
1243浏览 • 1回复 待解决
HarmonyOS List怎么刷新数据
836浏览 • 1回复 待解决
HarmonyOS List组件动态刷新数据问题
1901浏览 • 1回复 待解决
HarmonyOS 下拉刷新时候没有更新数据
1323浏览 • 1回复 待解决
HarmonyOS rn组件FlatList下拉刷新异常
857浏览 • 1回复 待解决
HarmonyOS list数据刷新,头像闪烁
593浏览 • 1回复 待解决
上拉加载,下拉刷新组件
1135浏览 • 1回复 待解决
HarmonyOS UI和ViewModel如何刷新数据
687浏览 • 1回复 待解决
HarmonyOS 更新数据UI刷新
1035浏览 • 1回复 待解决