HarmonyOS SegmentButton 点击事件回调是哪个? onclick无回调

用户点击切换SegmentButton 时,无回调, 回调需要获取到点击按钮的index

HarmonyOS
2024-12-20 16:12:33
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

参考以下demo:

import {
  ItemRestriction,
  SegmentButton,
  SegmentButtonItemTuple,
  SegmentButtonOptions,
  SegmentButtonTextItem
} from '@ohos.ArkUI.advanced.SegmentButton'

@Entry
@Component
struct Index {
  @State tabOptions: SegmentButtonOptions = SegmentButtonOptions.tab({
    buttons: [{ text: '页签按钮1' }, { text: '页签按钮2' }, {
      text: '页签按钮3'
    }] as ItemRestriction<SegmentButtonTextItem>,
    backgroundBlurStyle: BlurStyle.BACKGROUND_THICK
  })

  @State tf:boolean=true
  @State @Watch('onSegmentButtonChange') tabSelectedIndexes: number[] = [0]
  onSegmentButtonChange() {
    this.tf=!this.tf
    console.log(`选中按钮索引 -- ${this.tabSelectedIndexes}`);
  }
  aboutToAppear(): void {
    console.log("122233")
  }

  build() {
    Row() {
      Column() {
        Column({ space: 25 }) {
          SegmentButton({ options: this.tabOptions,
            selectedIndexes: $tabSelectedIndexes })
          TextInput({text:`${this.tabSelectedIndexes}`}).enabled(this.tf)
        }.width('90%')
      }.width('100%')
    }.height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
分享
微博
QQ
微信
回复
2024-12-20 18:07:34


相关问题
HarmonyOS 点击事件方法
1067浏览 • 1回复 待解决
HarmonyOS 事件
1060浏览 • 1回复 待解决
HarmonyOS Grid拖拽
620浏览 • 1回复 待解决
HarmonyOS Scroll组件事件问题
1008浏览 • 1回复 待解决
HarmonyOS 登录组件点击隐私没有
685浏览 • 1回复 待解决
焦点事件onBlur/onFocus无法触发
2900浏览 • 1回复 待解决
HarmonyOS Watch没有
831浏览 • 1回复 待解决
HarmonyOS Web组件
1221浏览 • 1回复 待解决
HarmonyOS onNewWant未
632浏览 • 1回复 待解决
interface如何调用
1440浏览 • 1回复 待解决