index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { VantComponent } from '../common/component';
  2. import { addUnit } from '../common/utils';
  3. VantComponent({
  4. field: true,
  5. relation: {
  6. name: 'radio-group',
  7. type: 'ancestor',
  8. linked(target) {
  9. this.parent = target;
  10. },
  11. unlinked() {
  12. this.parent = null;
  13. }
  14. },
  15. classes: ['icon-class', 'label-class'],
  16. props: {
  17. value: null,
  18. disabled: Boolean,
  19. useIconSlot: Boolean,
  20. checkedColor: String,
  21. labelPosition: {
  22. type: String,
  23. value: 'right'
  24. },
  25. labelDisabled: Boolean,
  26. shape: {
  27. type: String,
  28. value: 'round'
  29. },
  30. iconSize: {
  31. type: null,
  32. observer: 'setIconSizeUnit'
  33. }
  34. },
  35. data: {
  36. iconSizeWithUnit: '20px'
  37. },
  38. methods: {
  39. setIconSizeUnit(val) {
  40. this.setData({
  41. iconSizeWithUnit: addUnit(val)
  42. });
  43. },
  44. emitChange(value) {
  45. const instance = this.parent || this;
  46. instance.$emit('input', value);
  47. instance.$emit('change', value);
  48. },
  49. onChange(event) {
  50. console.log(event);
  51. this.emitChange(this.data.name);
  52. },
  53. onClickLabel() {
  54. const { disabled, labelDisabled, name } = this.data;
  55. if (!disabled && !labelDisabled) {
  56. this.emitChange(name);
  57. }
  58. }
  59. }
  60. });