StdRadioGroup.vue 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <a-radio-group name="radioGroup" v-model="data" @change="onChange">
  3. <a-radio :value="k" v-for="(v,k) in options" :key="k">
  4. {{ v }}
  5. </a-radio>
  6. </a-radio-group>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'StdRadioGroup',
  11. props: {
  12. options: [Object,Array],
  13. value: {
  14. type: [String, Number]
  15. },
  16. keyType: String
  17. },
  18. model: {
  19. prop: 'value',
  20. event: 'changeValue'
  21. },
  22. data() {
  23. return {
  24. data: this.value?.toString() ?? '',
  25. }
  26. },
  27. watch: {
  28. value() {
  29. this.data = this.value.toString()
  30. }
  31. },
  32. methods: {
  33. onChange(e) {
  34. if (this.keyType === 'int') {
  35. this.data = e.target.value
  36. this.$emit('changeValue', parseInt(e.target.value))
  37. } else {
  38. this.$emit('changeValue', e.target.value)
  39. }
  40. }
  41. }
  42. }
  43. </script>
  44. <style scoped>
  45. </style>