复选框 Checkbox

基本用法

复选框 Checkbox - 图1

  1. <template lang="html">
  2. <div>
  3. <div class="demo-hidden">
  4. <za-panel>
  5. <za-panel-header title="基本"></za-panel-header>
  6. <za-panel-body>
  7. <za-cell>
  8. <za-checkbox v-model='v1' @change='handleChange'>普通</za-checkbox>
  9. </za-cell>
  10. <za-cell>
  11. <za-checkbox v-model='v2' @change='handleChange'>选中</za-checkbox>
  12. </za-cell>
  13. <za-cell>
  14. <za-checkbox v-model='v3' @change='handleChange' disabled>禁止</za-checkbox>
  15. </za-cell>
  16. <za-cell>
  17. <za-checkbox v-model='v4' @change='handleChange' disabled>选中且禁止</za-checkbox>
  18. </za-cell>
  19. </za-panel-body>
  20. </za-panel>
  21. <za-panel>
  22. <za-panel-header title="单列样式"></za-panel-header>
  23. <za-panel-body>
  24. <za-checkbox v-model='v5' @change='handleChange' type='cell'>阅读并同意《XXX条款》中的相关规定</za-checkbox>
  25. </za-panel-body>
  26. </za-panel>
  27. <za-panel>
  28. <za-panel-header title="组合使用"></za-panel-header>
  29. <za-panel-body>
  30. <za-cell>
  31. <za-checkbox-group v-model='checkboxGroup' slot='description' @change='handleGroupChange'>
  32. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city" :disabled='index === 2'>{{city}}</za-checkbox>
  33. </za-checkbox-group>
  34. 组合使用
  35. </za-cell>
  36. </za-panel-body>
  37. </za-panel>
  38. <za-panel>
  39. <za-panel-header title="按钮样式"></za-panel-header>
  40. <za-panel-body>
  41. <za-cell>
  42. <za-checkbox-group
  43. v-model='checkboxGroup2'
  44. slot='description'
  45. type="button"
  46. @change='handleGroupChange'>
  47. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city">{{city}}</za-checkbox>
  48. </za-checkbox-group>
  49. 普通
  50. </za-cell>
  51. <za-cell>
  52. <za-checkbox-group
  53. v-model='checkboxGroup3'
  54. slot='description'
  55. type="button"
  56. @change='handleGroupChange'>
  57. <za-checkbox v-for='city in cities' :label="city" :key="city">{{city}}</za-checkbox>
  58. </za-checkbox-group>
  59. 指定默认值
  60. </za-cell>
  61. <za-cell>
  62. <za-checkbox-group
  63. v-model='checkboxGroup4'
  64. slot='description'
  65. type="button"
  66. @change='handleGroupChange'>
  67. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city" :disabled='index === 2'>{{city}}</za-checkbox>
  68. </za-checkbox-group>
  69. 禁用指定项
  70. </za-cell>
  71. <za-cell>
  72. <za-checkbox-group
  73. v-model='checkboxGroup5'
  74. slot='description'
  75. type="button"
  76. shape="radius"
  77. @change='handleGroupChange'>
  78. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city">{{city}}</za-checkbox>
  79. </za-checkbox-group>
  80. 圆角
  81. </za-cell>
  82. <za-cell>
  83. <za-checkbox-group
  84. v-model='checkboxGroup6'
  85. slot='description'
  86. type="button"
  87. shape="round"
  88. @change='handleGroupChange'>
  89. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city">{{city}}</za-checkbox>
  90. </za-checkbox-group>
  91. 椭圆角
  92. </za-cell>
  93. </za-panel-body>
  94. </za-panel>
  95. <za-panel>
  96. <za-panel-header title="块级样式"></za-panel-header>
  97. <za-panel-body style='padding:10px'>
  98. <za-checkbox-group
  99. v-model='checkboxGroupCompact2'
  100. type="button"
  101. block
  102. shape="radius"
  103. @change='handleGroupChange'>
  104. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city" :disabled='index === 2'>{{city}}</za-checkbox>
  105. </za-checkbox-group>
  106. </za-panel-body>
  107. </za-panel>
  108. <za-panel>
  109. <za-panel-header title="列表组样式"></za-panel-header>
  110. <za-panel-body>
  111. <za-checkbox-group
  112. v-model='checkboxGroup7'
  113. type="cell"
  114. @change='handleGroupChange'>
  115. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city" :disabled='index === 2'>{{city}}</za-checkbox>
  116. </za-checkbox-group>
  117. </za-panel-body>
  118. </za-panel>
  119. <za-panel>
  120. <za-panel-header title="列表样式禁用状态"></za-panel-header>
  121. <za-panel-body>
  122. <za-checkbox-group
  123. v-model='checkboxGroup8'
  124. type="cell"
  125. disabled
  126. @change='handleGroupChange'>
  127. <za-checkbox v-for='(city, index) in cities' :label="city" :key="city">{{city}}</za-checkbox>
  128. </za-checkbox-group>
  129. </za-panel-body>
  130. </za-panel>
  131. </div>
  132. </div>
  133. </template>
  134. <script>
  135. export default {
  136. data() {
  137. return {
  138. v1: false,
  139. v2: true,
  140. v3: false,
  141. v4: true,
  142. v5: false,
  143. cities: ['上海', '北京', '广州', '深圳'],
  144. checkboxGroup: ['上海'],
  145. checkboxGroup2: [],
  146. checkboxGroup3: ['上海', '北京'],
  147. checkboxGroup4: [],
  148. checkboxGroup5: [],
  149. checkboxGroup6: [],
  150. checkboxGroup7: [],
  151. checkboxGroup8: [],
  152. checkboxGroupCompact: [],
  153. checkboxGroupCompact2: [],
  154. }
  155. },
  156. methods: {
  157. handleChange(v, e) {
  158. console.log(v, e);
  159. },
  160. handleGroupChange(v, e){
  161. console.log(v, e);
  162. },
  163. },
  164. };
  165. </script>

API

Checkbox Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-checkbox类名前缀
themestring'primary''default', 'primary', 'info', 'success', 'warning', 'error'主题
typestring'button', 'cell'显示类型
v-modelboolfalse绑定变量
disabledboolfalse是否禁用

Checkbox Events

事件名称说明回调参数
change当绑定值变化时触发的事件1.选中的值列表,2.event 事件对象

Checkbox-Group Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-checkbox类名前缀
themestring'primary''default', 'primary', 'info', 'success', 'warning', 'error'主题
shapestring'radius', 'round'形状
typestring'button', 'cell'显示类型
v-modelarray[ ]绑定变量
blockboolfalse是否为块级元素
disabledboolfalse是否禁用