可以参考下demo@Entry @Component struct SearchSwiperPage { @State message: string = 'Hello World'; @State index: number = 0 private swiperController: SwiperController = new SwiperController() @State searchTextSwiper: string[] = [ '111111' ] aboutToAppear(): void { setInterval(() => { this.searchTextSwiper.push(Math.random().toString()) }, 5000); setInterval(() => { this.swiperController.showNext() }, 5200); setInterval(() => { this.searchTextSwiper = [this.searchTextSwiper[1]] this.index = 0 }, 6000); } build() { Row() { Column() { Swiper(this.swiperController) { ForEach(this.searchTextSwiper, (item: Resource) => { Column() { Text(item) .fontSize(13) .fontColor(Color.Black) } .alignItems(HorizontalAlign.Start) }, (item: Resource) => JSON.stringify(item)) } .autoPlay(false) .loop(false) .vertical(true) .indicator(false) .index(this.index) } .width('100%') } .height('100%') } }
可以参考下demo