Skip to content

单选示例

vue
<template>
  <view style="padding: 40rpx;">
    <ex-btn-group :list="list" v-model="value"></ex-btn-group>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          label: "A",
          list: [
            {
              label: "阿坝",
              value: "00",
            },
            {
              label: "阿克苏",
              value: "01",
            },
          ],
        },
        {
          label: "B",
          list: [
            {
              label: "北京",
              value: "10",
            },
            {
              label: "白城",
              value: "11",
            },
            {
              label: "百色",
              value: "12",
            },
            {
              label: "白山",
              value: "13",
            },
          ],
        },
      ],
      value: "04", // 多选时候为数组
    };
  },
};
</script>

<style lang="scss" scoped></style>

多选示例

vue
<template>
  <view style="padding: 40rpx;">
    <ex-btn-group :list="list" v-model="value" multiple></ex-btn-group>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [
        {
          label: "A",
          list: [
            {
              label: "阿坝",
              value: "00",
            },
            {
              label: "阿克苏",
              value: "01",
            },
          ],
        },
        {
          label: "B",
          list: [
            {
              label: "北京",
              value: "10",
            },
            {
              label: "白城",
              value: "11",
            },
            {
              label: "百色",
              value: "12",
            },
            {
              label: "白山",
              value: "13",
            },
          ],
        },
      ],
      value: ["04"], // 多选时候为数组
    };
  },
};
</script>

<style lang="scss" scoped></style>

自定义分组标签插槽

vue
<template>
  <view style="padding: 40rpx;">
    <ex-btn-group :list="list" v-model="value">
      <template v-slot:label="{ item, index }">
        <view class="tag">
          <text>{{ item.label }}</text>
          <text>更多{{ index }}(插槽自定义)</text>
        </view>
      </template>
    </ex-btn-group>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      list: [
        {
          label: "A",
          list: [
            {
              label: "阿坝",
              value: "00",
            },
            {
              label: "阿克苏",
              value: "01",
            },
          ],
        },
        {
          label: "B",
          list: [
            {
              label: "北京",
              value: "10",
            },
            {
              label: "白城",
              value: "11",
            },
            {
              label: "百色",
              value: "12",
            },
            {
              label: "白山",
              value: "13",
            },
          ],
        },
      ],
      value: "04", // 多选时候为数组
    };
  },
};
</script>

<style lang="scss" scoped>
.tag {
  margin: 20rpx 0;
  display: flex;
  justify-content: space-between;
  color: red;
}
</style>

属性

属性名类型默认值可选值说明
listArray二维数组,格式见下方示例
showFilterBooleantruetrue,false是否显示过滤输入框
filterKeysArray['label']过滤字段 key,默认 label 支持多个字段,数组传递
propsObject{label:'label',subListKey:'list', childProps:{label:'label',value:'value' }}配置项
multipleBooleanfalsetrue,false按钮是否多选
maxNumNumberInfinity最大选中数量, 仅多选有效
maxNumToastString超出最大选中数量超出最大选中数量的提示信息
cancelSelectItemBooleantruetrue,false选中的选项再次点击能否取消选中,默认 true
disabledArrArray[]禁用选项
lineNumberNumber3每行按钮个数
gapString12px按钮间距
selectedStyleObject{background: '#409eff',color: '#FFFFFF',borderColor: '#409eff'}自定义按钮选中样式
unSelectedStyleObject{background: '#F5F5F5', color: '#4D4D4D',borderColor: '#F5F5F5'}自定义按钮未选中样式
disabledStyleObject{background: '#e9e9eb',color: '#bcbec2',borderColor: '#e9e9eb'}按钮禁用的样式
showBadgeBooleanfalse是否显示选中角标
badgePositionStringtoptop,bottom选中角标的位置
badgeSizeString16px角标的大小
badgeColorString#cdcdcd角标默认颜色
badgeSelectedColorString#409eff角标选中颜色
badgeDisabledColorString#bcbec2角标禁用颜色

list 配置项

属性名类型默认值可选值说明
labelString,Number分组 key
listArray子分组数组

list 数据格式

js
const list = [
  {
    label: "A",
    list: [
      {
        label: "阿坝",
        value: "00",
      },
      {
        label: "阿克苏",
        value: "01",
      },
    ],
  },
  {
    label: "B",
    list: [
      {
        label: "北京",
        value: "10",
      },
      {
        label: "白城",
        value: "11",
      },
      {
        label: "百色",
        value: "12",
      },
      {
        label: "白山",
        value: "13",
      },
    ],
  },
];

事件

事件名说明
itemClick选项点击事件