参考如下demo@Entry @Component struct TabsDemo { @State list2: string[] = ['要闻6', '要闻7', '要闻8', '要闻9', '要闻10', '要闻11', '要闻12', '要闻13', '要闻14', '要闻15', '要闻16', '要闻17', '要闻18', '要闻19', '要闻20'] @State currentIndex: number = 1 // aboutToAppear(): void { // setTimeout(() => { // this.list2 = ['要闻6', '要闻7', // '要闻8', '要闻9', '要闻10', '要闻11', '要闻12', '要闻13', '要闻14', // '要闻15', '要闻16', '要闻17', '要闻18', '要闻19', '要闻20'] // }, 1000) // } build() { Tabs({ index: this.currentIndex }) { ForEach(this.list2, (channel: string, index: number) => { TabContent() { Column() { Text(channel).width('100%').height('100%').textAlign(TextAlign.Center); } } .tabBar(channel) }) } .barMode(BarMode.Scrollable) .onChange((index: number) => { this.currentIndex = index }) } }
参考如下demo