index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <u-radio-group class="jnpf-radio" v-model="innerValue" :disabled="disabled"
  3. :wrap="direction == 'horizontal' ? false : true" @change="onChange">
  4. <u-radio v-for="(item, index) in options" :key="index" :name="item[props.value]">
  5. {{ item[props.label] }}
  6. </u-radio>
  7. </u-radio-group>
  8. </template>
  9. <script>
  10. export default {
  11. inheritAttrs: false,
  12. name: 'jnpfRadio',
  13. props: {
  14. modelValue: {
  15. type: [String, Number, Boolean],
  16. },
  17. direction: {
  18. type: String,
  19. default: "horizontal"
  20. },
  21. options: {
  22. type: Array,
  23. default: () => []
  24. },
  25. props: {
  26. type: Object,
  27. default: () => ({
  28. label: 'fullName',
  29. value: 'id'
  30. })
  31. },
  32. disabled: {
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. data() {
  38. return {
  39. innerValue: ''
  40. }
  41. },
  42. watch: {
  43. modelValue: {
  44. handler(val) {
  45. this.innerValue = val
  46. },
  47. immediate: true,
  48. }
  49. },
  50. methods: {
  51. onChange(value, e) {
  52. const selectData = this.options.filter(o => value == o[this.props.value]) || []
  53. this.$emit('update:modelValue', value)
  54. this.$emit('change', value, selectData[0])
  55. },
  56. }
  57. }
  58. </script>