ut-radio.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <view class="d-flex gap-20">
  3. <view v-for="option in options" :key="option.value" :class="{ 'active': modelValue == option.value }" class="pd-20 f-s-26 min-180 text-center radius-10 ut-radio-item" @click="onSelect(option.value)">
  4. {{ option.label }}
  5. </view>
  6. </view>
  7. </template>
  8. <script setup lang="ts">
  9. const props = defineProps({
  10. options: { type: Array<{label: '', value: '' }>, default: () => [] },
  11. modelValue: { type: null, default: null },
  12. disabled: { type: Boolean, default: false },
  13. });
  14. const emit = defineEmits<{
  15. (e: 'update:modelValue', value: any): void;
  16. (e: 'change', value: any): void;
  17. }>();
  18. const onSelect = (value: any) => {
  19. if (props.disabled) return;
  20. if (value === props.modelValue) return;
  21. emit('update:modelValue', value);
  22. emit('change', value);
  23. };
  24. </script>
  25. <style scoped lang="scss">
  26. .ut-radio-item {
  27. background-color: #F2F2F2;
  28. &.active {
  29. color: #fff;
  30. background-color: $u-primary;
  31. }
  32. }
  33. </style>