index.vue 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <uni-shadow-root class="vant-checkbox-group-index"><slot></slot></uni-shadow-root>
  3. </template>
  4. <script>
  5. global['__wxRoute'] = 'vant/checkbox-group/index'
  6. import { VantComponent } from '../common/component';
  7. VantComponent({
  8. field: true,
  9. relation: {
  10. name: 'checkbox',
  11. type: 'descendant',
  12. linked(target) {
  13. this.children = this.children || [];
  14. this.children.push(target);
  15. this.updateChild(target);
  16. },
  17. unlinked(target) {
  18. this.children = this.children.filter((child) => child !== target);
  19. }
  20. },
  21. props: {
  22. max: Number,
  23. value: {
  24. type: Array,
  25. observer: 'updateChildren'
  26. },
  27. disabled: {
  28. type: Boolean,
  29. observer: 'updateChildren'
  30. }
  31. },
  32. methods: {
  33. updateChildren() {
  34. (this.children || []).forEach((child) => this.updateChild(child));
  35. },
  36. updateChild(child) {
  37. const { value, disabled } = this.data;
  38. child.set({
  39. value: value.indexOf(child.data.name) !== -1,
  40. disabled: disabled || child.data.disabled
  41. });
  42. }
  43. }
  44. });
  45. export default global['__wxComponents']['vant/checkbox-group/index']
  46. </script>
  47. <style platform="mp-weixin">
  48. @import '../common/index.css';
  49. </style>