示例代码:
interface newRepeatItem {
item: string,
index: number
}
@State newTabsList: Array<string> = []
Tabs({ barPosition: BarPosition.Start }) {
Repeat(this.newTabsList)
.each((obj: newRepeatItem) => {
TabContent() {
Text(obj.item)
}.width('100%')
.height('100%')
.backgroundColor(Color.Brown)
.tabBar(obj.item)
})
.key((item: string, index: number) => index.toString()) }
.onChange((index: number) => {
this.currentIndex = index
})
.barHeight(50)
.barMode(BarMode.Scrollable)
}
setTimeout(() => {
this.newTabsList.push('关注1')
this.newTabsList.push('关注2')
this.newTabsList.push('关注3')
}, 1000)
请参考demo: