evan-radio-group.vue 894 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <view class="evan-radio-group">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'EvanRadioGroup',
  9. props: {
  10. value: {
  11. type: [String, Number, Boolean],
  12. default: null
  13. },
  14. disabled: {
  15. type: Boolean,
  16. default: false
  17. }
  18. },
  19. watch: {
  20. value: {
  21. handler(value) {
  22. this.deepSetValue(this.$children)
  23. }
  24. }
  25. },
  26. methods: {
  27. onRadioChange(label) {
  28. this.$emit('input', label)
  29. this.$emit('change', label)
  30. },
  31. deepSetValue(array) {
  32. if (Array.isArray(array)) {
  33. array.forEach((child) => {
  34. let childName = child.$options.name
  35. if (childName === 'EvanRadio') {
  36. if (typeof child.setValue === 'function') {
  37. child.setValue(this.value)
  38. }
  39. } else if (child.$children) {
  40. this.deepSetValue(child.$children)
  41. }
  42. })
  43. }
  44. }
  45. }
  46. }
  47. </script>
  48. <style>
  49. </style>