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
  }
}
HarmonyOS
1天前
浏览
收藏 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
  }
}
分享
微博
QQ
微信
回复
1天前
相关问题
HarmonyOS使用Refresh下拉刷新问题
943浏览 • 1回复 待解决
Refresh结合lottie实现下拉刷新动画
1152浏览 • 1回复 待解决
HarmonyOS List组件动态刷新数据问题
1057浏览 • 1回复 待解决
HarmonyOS List怎么刷新数据
48浏览 • 1回复 待解决
HarmonyOS 组件下拉刷新问题
517浏览 • 1回复 待解决
HarmonyOS list数据刷新,头像闪烁
32浏览 • 1回复 待解决
上拉加载,下拉刷新组件
452浏览 • 1回复 待解决
HarmonyOS rn组件FlatList下拉刷新异常
31浏览 • 1回复 待解决
HarmonyOS Web组件怎么添加下拉刷新
79浏览 • 1回复 待解决
HarmonyOS 下拉刷新功能
225浏览 • 1回复 待解决