示例:@Entry @Component struct Tabbar_vertical { @State tabArray: Array<number> = [0, 1, 2] @State focusIndex: number = 0 @State index: number = 0 private controller: TabsController = new TabsController() @Builder Tab(tabName: string, tabItem: number, tabIndex: number) { Column() { Text(tabName).fontSize(18) } .width(100) .height(40) .onClick(() => { this.controller.changeIndex(tabIndex) this.focusIndex = tabIndex }) .backgroundColor(tabIndex === this.focusIndex ? "#ffffffff" : "#ffb7b7b7") .justifyContent(FlexAlign.Center) } build() { Column() { Row() { //页签展示 Column() { Scroll() { Column({ space: 10 }) { ForEach(this.tabArray, (item: number, index: number) => { this.Tab("页面" + item, item, index) }) } //设置从顶部排列 .justifyContent(FlexAlign.Start).height('100%') } .scrollable(ScrollDirection.Vertical) } .width('30%') .backgroundColor("#ffb7b7b7") //tabs Tabs({ barPosition: BarPosition.Start, controller: this.controller }) { ForEach(this.tabArray, (item: number, index: number) => { TabContent() { Text('我是页面 ' + item + " 的内容") .height(300) .width('100%') .fontSize(30) } .backgroundColor('#ffbdf38d') }) } .barHeight(0) .animationDuration(100) .onChange((index: number) => { console.log('foo change') this.focusIndex = index }) .width('70%') } } .height('100%') } }
示例: