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%')
  }
}
分享
微博
QQ
微信
回复
2024-12-20 18:07:34
相关问题
HarmonyOS 点击事件方法
516浏览 • 1回复 待解决
HarmonyOS 事件
505浏览 • 1回复 待解决
HarmonyOS Grid拖拽
279浏览 • 1回复 待解决
HarmonyOS Scroll组件事件问题
566浏览 • 1回复 待解决
HarmonyOS 登录组件点击隐私没有
257浏览 • 1回复 待解决
焦点事件onBlur/onFocus无法触发
2338浏览 • 1回复 待解决
HarmonyOS Watch没有
381浏览 • 1回复 待解决
HarmonyOS onNewWant未
224浏览 • 1回复 待解决
HarmonyOS Web组件
679浏览 • 1回复 待解决
interface如何调用
1093浏览 • 1回复 待解决