CheckGroup 选择项组

Scan me!

无 UI 的抽象选择项基础组件, 可根据具体场景自定义样式. 1.5.0+

引入

  1. import { CheckGroup } from 'mand-mobile'
  2. Vue.component(CheckGroup.name, CheckGroup)

代码演示

单选

  1. <template>
  2. <div class="md-example-child md-example-child-single-component">
  3. <md-check-group
  4. v-model="selected"
  5. :options="options"
  6. >
  7. <div slot-scope="{ option, select }" @click="select(option.value)">
  8. label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
  9. </div>
  10. </md-check-group>
  11. </div>
  12. </template>
  13. <script>
  14. import {CheckGroup} from 'mand-mobile'
  15. export default {
  16. name: 'check-group-demo',
  17. title: '单选',
  18. components: {
  19. [CheckGroup.name]: CheckGroup,
  20. },
  21. data() {
  22. return {
  23. selected: '1',
  24. options: [
  25. {value: '1', label: '无UI'},
  26. {value: '2', label: '禁用选项', disabled: true},
  27. {value: '3', label: '点我啊'},
  28. {value: '4', label: '点我啊'},
  29. {value: '5', label: '点我啊'},
  30. {value: '6', label: '点我啊'},
  31. ],
  32. }
  33. },
  34. }
  35. </script>
  36. <style lang="stylus" scoped>
  37. .md-example-child
  38. font-size 28px
  39. </style>
  40.  

至多3个

  1. <template>
  2. <div class="md-example-child md-example-child-single-component">
  3. <md-check-group
  4. v-model="selected"
  5. :options="options"
  6. :max="3"
  7. >
  8. <div slot-scope="{ option, select }" @click="select(option.value)">
  9. label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
  10. </div>
  11. </md-check-group>
  12. </div>
  13. </template>
  14. <script>
  15. import {CheckGroup} from 'mand-mobile'
  16. export default {
  17. name: 'check-group-demo',
  18. title: '至多3个',
  19. components: {
  20. [CheckGroup.name]: CheckGroup,
  21. },
  22. data() {
  23. return {
  24. selected: '1',
  25. options: [
  26. {value: '1', label: '选项一'},
  27. {value: '2', label: '选项二', disabled: true},
  28. {value: '3', label: '选项三'},
  29. {value: '4', label: '选项四'},
  30. {value: '5', label: '选项五'},
  31. {value: '6', label: '选项六'},
  32. ],
  33. }
  34. },
  35. }
  36. </script>
  37. <style lang="stylus" scoped>
  38. .md-example-child
  39. font-size 28px
  40. </style>
  41.  

多选

  1. <template>
  2. <div class="md-example-child md-example-child-single-component">
  3. <md-check-group
  4. v-model="selected"
  5. :options="options"
  6. :max="0"
  7. >
  8. <div slot-scope="{ option, select }" @click="select(option.value)">
  9. label: {{option.label}}, disabled: {{!!option.disabled}}, isSelected: {{option.isSelected}}
  10. </div>
  11. </md-check-group>
  12. </div>
  13. </template>
  14. <script>
  15. import {CheckGroup} from 'mand-mobile'
  16. export default {
  17. name: 'check-group-demo',
  18. title: '多选',
  19. components: {
  20. [CheckGroup.name]: CheckGroup,
  21. },
  22. data() {
  23. return {
  24. selected: '1',
  25. options: [
  26. {value: '1', label: '选项一'},
  27. {value: '2', label: '选项二', disabled: true},
  28. {value: '3', label: '选项三'},
  29. {value: '4', label: '选项四'},
  30. {value: '5', label: '选项五'},
  31. {value: '6', label: '选项六'},
  32. ],
  33. }
  34. },
  35. }
  36. </script>
  37. <style lang="stylus" scoped>
  38. .md-example-child
  39. font-size 28px
  40. </style>
  41.  

API

CheckGroup Props

属性说明类型默认值备注
v-model选中的值[String,Array]-若为单选则用String, 若为多选则是Array
options选择项数组Array--
max最多选择几项Number1为1为单选,为0不限制数量,大于1则是限制至多选择数量
disabled是否禁用选择Booleanfalse-
options

选择项数组格式如下,其中value值必填, 其余为选填, 可添加自定义字段。

  1. [
  2. { value: '', disabled: false }
  3. ]

CheckGroup Methods

select(value)
参数说明类型默认值
value即将新增的选中选项值[String, Array]-

CheckGroup Slots

CheckGroup的默认插槽将被作为列表项模板使用, 会暴露{option, select}slot-scope使用。其中option在原有选项配置对象里新增了isSelected字段布尔值。

  1. <md-check-group
  2. v-model="selected"
  3. :options="options"
  4. >
  5. <div slot-scope="{ option, select }" @click="select(option.value)">
  6. ...
  7. </div>
  8. </md-check-group>