index.js 1003 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. field: true,
  4. relation: {
  5. name: 'radio',
  6. type: 'descendant',
  7. linked(target) {
  8. this.children = this.children || [];
  9. this.children.push(target);
  10. this.updateChild(target);
  11. },
  12. unlinked(target) {
  13. this.children = this.children.filter((child) => child !== target);
  14. }
  15. },
  16. props: {
  17. value: {
  18. type: null,
  19. observer: 'updateChildren'
  20. },
  21. disabled: {
  22. type: Boolean,
  23. observer: 'updateChildren'
  24. }
  25. },
  26. methods: {
  27. updateChildren() {
  28. (this.children || []).forEach((child) => this.updateChild(child));
  29. },
  30. updateChild(child) {
  31. const { value, disabled } = this.data;
  32. child.setData({
  33. value,
  34. disabled: disabled || child.data.disabled
  35. });
  36. }
  37. }
  38. });