SegmentedControl 分段器

分段器由至少 2 个分段控件组成,用作不同视图的显示,预设 9 种颜色 light, stable, positive, calm, assertive, balanced, energized, royal, dark 可选用。

使用指南

在 page.json 中引入组件

  1. {
  2. "navigationBarTitleText": "SegmentedControl",
  3. "usingComponents": {
  4. "wux-segmented-control": "../../dist/segmented-control/index"
  5. }
  6. }

示例

  1. <view class="page">
  2. <view class="page__hd">
  3. <view class="page__title">SegmentedControl</view>
  4. <view class="page__desc">分段器</view>
  5. </view>
  6. <view class="page__bd">
  7. <view class="sub-title">Default</view>
  8. <wux-segmented-control values="{{ ['Segment1', 'Segment2'] }}" />
  9. <view class="sub-title">Theme</view>
  10. <wux-segmented-control theme="light" values="{{ ['Segment1', 'Segment2'] }}" />
  11. <wux-segmented-control theme="stable" values="{{ ['Segment1', 'Segment2'] }}" />
  12. <wux-segmented-control theme="positive" values="{{ ['Segment1', 'Segment2'] }}" />
  13. <wux-segmented-control theme="calm" values="{{ ['Segment1', 'Segment2'] }}" />
  14. <wux-segmented-control theme="balanced" values="{{ ['Segment1', 'Segment2'] }}" />
  15. <wux-segmented-control theme="energized" values="{{ ['Segment1', 'Segment2'] }}" />
  16. <wux-segmented-control theme="assertive" values="{{ ['Segment1', 'Segment2'] }}" />
  17. <wux-segmented-control theme="royal" values="{{ ['Segment1', 'Segment2'] }}" />
  18. <wux-segmented-control theme="dark" values="{{ ['Segment1', 'Segment2'] }}" />
  19. <view class="sub-title">Disabled</view>
  20. <wux-segmented-control disabled values="{{ ['Segment1', 'Segment2'] }}" />
  21. <view class="sub-title">DefaultCurrent</view>
  22. <wux-segmented-control default-current="2" values="{{ ['Segment1', 'Segment2', 'Segment3'] }}" />
  23. <view class="sub-title">Controlled</view>
  24. <wux-segmented-control current="{{ current }}" controlled values="{{ ['Segment1', 'Segment2', 'Segment3'] }}" bind:change="onChange" />
  25. </view>
  26. </view>
  1. Page({
  2. data: {
  3. current: 1,
  4. },
  5. onLoad() {
  6. this.key = Math.floor(Math.random() * 3)
  7. },
  8. onChange(e) {
  9. console.log(e)
  10. if (e.detail.key === this.key) {
  11. return wx.showModal({
  12. title: 'No switching is allowed',
  13. showCancel: !1,
  14. })
  15. }
  16. this.setData({
  17. current: e.detail.key,
  18. })
  19. },
  20. })

视频演示

SegmentedControl

API

SegmentedControl props

参数 类型 描述 默认值
prefixCls string 自定义类名前缀 wux-segment
theme string 主题色,可选值为 light、stable、positive、calm、assertive、balanced、energized、royal、dark balanced
defaultCurrent number 默认激活 tab 面板的 key,当 controlledfalse 时才生效 0
current number 用于手动激活 tab 面板的 key,当 controlledtrue 时才生效 0
controlled boolean 是否受控 说明文档 false
disabled boolean 是否禁用 false
values array 选项数组 []
bind:change function 切换面板的回调函数 -

SegmentedControl externalClasses

名称 描述
wux-class 根节点样式类