CheckGroup 选择项组
无 UI 的抽象选择项基础组件, 可根据具体场景自定义样式. 1.5.0+
引入
import { CheckGroup } from 'mand-mobile'
Vue.component(CheckGroup.name, CheckGroup)
代码演示
单选
<template>
<div class="md-example-child md-example-child-single-component">
<md-check-group
v-model="selected"
:options="options"
>
<div slot-scope="{ option, select }" @click="select(option.value)">
label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
</div>
</md-check-group>
</div>
</template>
<script>
import {CheckGroup} from 'mand-mobile'
export default {
name: 'check-group-demo',
title: '单选',
components: {
[CheckGroup.name]: CheckGroup,
},
data() {
return {
selected: '1',
options: [
{value: '1', label: '无UI'},
{value: '2', label: '禁用选项', disabled: true},
{value: '3', label: '点我啊'},
{value: '4', label: '点我啊'},
{value: '5', label: '点我啊'},
{value: '6', label: '点我啊'},
],
}
},
}
</script>
<style lang="stylus" scoped>
.md-example-child
font-size 28px
</style>
至多3个
<template>
<div class="md-example-child md-example-child-single-component">
<md-check-group
v-model="selected"
:options="options"
:max="3"
>
<div slot-scope="{ option, select }" @click="select(option.value)">
label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
</div>
</md-check-group>
</div>
</template>
<script>
import {CheckGroup} from 'mand-mobile'
export default {
name: 'check-group-demo',
title: '至多3个',
components: {
[CheckGroup.name]: CheckGroup,
},
data() {
return {
selected: '1',
options: [
{value: '1', label: '选项一'},
{value: '2', label: '选项二', disabled: true},
{value: '3', label: '选项三'},
{value: '4', label: '选项四'},
{value: '5', label: '选项五'},
{value: '6', label: '选项六'},
],
}
},
}
</script>
<style lang="stylus" scoped>
.md-example-child
font-size 28px
</style>
多选
<template>
<div class="md-example-child md-example-child-single-component">
<md-check-group
v-model="selected"
:options="options"
:max="0"
>
<div slot-scope="{ option, select }" @click="select(option.value)">
label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
</div>
</md-check-group>
</div>
</template>
<script>
import {CheckGroup} from 'mand-mobile'
export default {
name: 'check-group-demo',
title: '多选',
components: {
[CheckGroup.name]: CheckGroup,
},
data() {
return {
selected: '1',
options: [
{value: '1', label: '选项一'},
{value: '2', label: '选项二', disabled: true},
{value: '3', label: '选项三'},
{value: '4', label: '选项四'},
{value: '5', label: '选项五'},
{value: '6', label: '选项六'},
],
}
},
}
</script>
<style lang="stylus" scoped>
.md-example-child
font-size 28px
</style>
API
CheckGroup Props
属性 | 说明 | 类型 | 默认值 | 备注 |
---|---|---|---|---|
v-model | 选中的值 | [String,Array] | - | 若为单选则用String , 若为多选则是Array |
options | 选择项数组 | Array | - | - |
max | 最多选择几项 | Number | 1 | 为1为单选,为0不限制数量,大于1则是限制至多选择数量 |
disabled | 是否禁用选择 | Boolean | false | - |
options
选择项数组格式如下,其中value
值必填, 其余为选填, 可添加自定义字段。
[
{ value: '', disabled: false }
]
CheckGroup Methods
select(value)
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
value | 即将新增的选中选项值 | [String, Array] | - |
CheckGroup Slots
CheckGroup
的默认插槽将被作为列表项模板使用, 会暴露{option, select}
给slot-scope
使用。其中option
在原有选项配置对象里新增了isSelected
字段布尔值。
<md-check-group
v-model="selected"
:options="options"
>
<div slot-scope="{ option, select }" @click="select(option.value)">
...
</div>
</md-check-group>