c-checkbox-group


复选框列表

示例

  1. <template>
  2. <page title="checkbox group演示">
  3. <view class="box">
  4. <c-checkbox-group
  5. option="{{ checkboxGroupOption1 }}"
  6. c-bind:groupchange="groupChangeHandler1"
  7. >
  8. </c-checkbox-group>
  9. </view>
  10. <view class="title">
  11. <text>selected value: {{ selected1 }}</text>
  12. </view>
  13. <view class="box">
  14. <c-checkbox-group
  15. option="{{ checkboxGroupOption2 }}"
  16. position="right"
  17. c-bind:groupchange="groupChangeHandler2"
  18. >
  19. </c-checkbox-group>
  20. </view>
  21. <view class="title">
  22. <text>selected value: {{ selected2 }}</text>
  23. </view>
  24. <view class="box">
  25. <c-checkbox-group
  26. option="{{ checkboxGroupOption3 }}"
  27. c-bind:groupchange="groupChangeHandler3"
  28. horizontal="{{ true }}"
  29. >
  30. </c-checkbox-group>
  31. </view>
  32. <view class="title">
  33. <text>selected value: {{ selected3 }}</text>
  34. </view>
  35. </page>
  36. </template>
  37. <script>
  38. class CCheckbox {
  39. data = {
  40. checkboxGroupOption1: [{
  41. checked: true,
  42. label: 'one',
  43. disabled: true
  44. }, {
  45. checked: false,
  46. label: 'two'
  47. }, {
  48. checked: false,
  49. label: 'three'
  50. }],
  51. selected1: 'one',
  52. checkboxGroupOption2: [{
  53. checked: true,
  54. label: 'one',
  55. disabled: true
  56. }, {
  57. checked: false,
  58. label: 'two'
  59. }, {
  60. checked: false,
  61. label: 'three'
  62. }],
  63. selected2: 'one',
  64. checkboxGroupOption3: [{
  65. checked: true,
  66. label: 'one',
  67. disabled: true
  68. }, {
  69. checked: false,
  70. label: 'two'
  71. }, {
  72. checked: false,
  73. label: 'three'
  74. }],
  75. selected3: 'one'
  76. }
  77. methods = {
  78. valueChange1 (e) {
  79. this.checkboxValue1 = e.detail.value
  80. },
  81. groupChangeHandler1 (e) {
  82. this.checkboxGroupOption1 = e.detail.value
  83. this.selected1 = e.detail.selected.join(', ')
  84. },
  85. groupChangeHandler2 (e) {
  86. this.checkboxGroupOption2 = e.detail.value
  87. this.selected2 = e.detail.selected.join(', ')
  88. },
  89. groupChangeHandler3 (e) {
  90. this.checkboxGroupOption3 = e.detail.value
  91. this.selected3 = e.detail.selected.join(', ')
  92. },
  93. valueChange2 (e) {
  94. this.checkboxValue2 = e.detail.value
  95. }
  96. }
  97. }
  98. export default new CCheckbox();
  99. </script>
  100. <style scoped>
  101. .container {
  102. position: absolute;
  103. top: 88cpx;
  104. left: 0;
  105. right: 0;
  106. bottom: 0;
  107. }
  108. .title {
  109. font-size: 38cpx;
  110. font-weight: 400;
  111. margin: 20cpx 0;
  112. padding: 8cpx 30cpx;
  113. background: #eee
  114. }
  115. .checkbox-value {
  116. font-size: 32cpx;
  117. }
  118. .box {
  119. margin: 10cpx 50cpx;
  120. }
  121. </style>
  122. <script cml-type="json">
  123. {
  124. "base": {
  125. "usingComponents": {
  126. "c-checkbox-group": "cml-ui/components/c-checkbox-group/c-checkbox-group"
  127. }
  128. }
  129. }
  130. </script>