customRadio.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="custom_radio_group">
  3. <view
  4. v-for="(item, idx) in options"
  5. :key="idx"
  6. class="radio_item"
  7. :class="{ active: modelValue === item.value }"
  8. @click="handleClick(item.value)"
  9. >
  10. <view class="radio_dot" :class="{ checked: modelValue === item.value }">
  11. <view v-if="modelValue === item.value" class="radio_inner"></view>
  12. </view>
  13. <text class="radio_text">{{ item.label }}</text>
  14. </view>
  15. </view>
  16. </template>
  17. <script setup>
  18. const props = defineProps({
  19. modelValue: {
  20. type: [Number, String],
  21. default: 0
  22. },
  23. options: {
  24. type: Array,
  25. default: () => []
  26. }
  27. });
  28. const emit = defineEmits(['update:modelValue']);
  29. const handleClick = (value) => {
  30. emit('update:modelValue', value);
  31. };
  32. </script>
  33. <style lang="scss" scoped>
  34. .custom_radio_group {
  35. display: flex;
  36. gap: 24rpx;
  37. .radio_item {
  38. display: flex;
  39. align-items: center;
  40. gap: 16rpx;
  41. .radio_dot {
  42. width: 32rpx;
  43. height: 32rpx;
  44. border-radius: 50%;
  45. border: 2rpx solid #DCDFE6;
  46. background-color: #FFFFFF;
  47. display: flex;
  48. align-items: center;
  49. justify-content: center;
  50. &.checked {
  51. border-color: #2E64FA;
  52. background-color: #FFFFFF;
  53. .radio_inner {
  54. width: 20rpx;
  55. height: 20rpx;
  56. border-radius: 50%;
  57. background-color: #2E64FA;
  58. }
  59. }
  60. }
  61. .radio_text {
  62. font-size: 28rpx;
  63. color: #333333;
  64. }
  65. }
  66. }
  67. </style>