index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <slot />
  4. </view>
  5. </template>
  6. <script>
  7. import { VantComponent } from '../common/component';
  8. export default {
  9. data() {
  10. return {
  11. parentDisabled: '',
  12. valueClone: []
  13. };
  14. },
  15. field: true,
  16. '../checkbox/index': {
  17. name: 'checkbox',
  18. type: 'descendant',
  19. current: 'checkbox-group',
  20. linked(target) {
  21. this.updateChild(target);
  22. }
  23. },
  24. props: {
  25. max: Number,
  26. value: {
  27. type: Array
  28. },
  29. disabled: {
  30. type: Boolean
  31. }
  32. },
  33. methods: {
  34. updateChildren() {
  35. (this.children || []).forEach((child) => this.updateChild(child));
  36. },
  37. updateChild(child) {
  38. const { valueClone: value, disabled } = this;
  39. child.setData({
  40. valueClone: value.indexOf(child.data.name) !== -1,
  41. parentDisabled: disabled
  42. });
  43. }
  44. },
  45. watch: {
  46. value: {
  47. handler: function () {
  48. this.valueClone = this.clone(this.value)(this.children || []).forEach((child) => this.updateChild(child));
  49. },
  50. immediate: true,
  51. deep: true
  52. },
  53. disabled: {
  54. handler: function () {
  55. (this.children || []).forEach((child) => this.updateChild(child));
  56. },
  57. immediate: true
  58. }
  59. }
  60. };
  61. </script>
  62. <style>
  63. @import './index.css';
  64. </style>