BtnRadio.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div class="btn-radio-wrap d-flex f-w-w">
  3. <template v-for="item in options" :key="item.value">
  4. <div class="btn-radio-item" @click="change(item.value)" :class="{ checked: item.value === activeName }">
  5. <template v-if="isNum"> {{ item.label }}({{ item.count }}) </template>
  6. <template v-else> {{ item.label }} </template>
  7. </div>
  8. </template>
  9. </div>
  10. </template>
  11. <script setup name="searchTabs" lang="ts">
  12. import { propTypes } from '@/utils/propTypes';
  13. const emit = defineEmits(['update:modelValue', 'change']);
  14. const activeName = ref('');
  15. const props = defineProps({
  16. modelValue: propTypes.string.def(''),
  17. options: propTypes.any.def([]),
  18. isNum: propTypes.bool.def(false)
  19. });
  20. const change = (event: any) => {
  21. activeName.value = event;
  22. emit('update:modelValue', event);
  23. emit('change', event);
  24. };
  25. watch(
  26. () => props.modelValue,
  27. async (val) => {
  28. if (val) {
  29. activeName.value = val as string;
  30. }
  31. },
  32. { deep: true, immediate: true }
  33. );
  34. </script>
  35. <style lang="scss" scoped>
  36. .btn-radio-wrap {
  37. .btn-radio-item {
  38. box-sizing: border-box;
  39. padding: 0 20px;
  40. height: 40px;
  41. line-height: 38px;
  42. color: #333;
  43. font-size: 14px;
  44. border: 1px solid var(--base-radio-border-color);
  45. border-radius: 4px;
  46. margin: 0 20px 20px 0;
  47. cursor: pointer;
  48. user-select: none;
  49. &.checked {
  50. background-color: var(--el-color-primary);
  51. color: #fff;
  52. border-color: var(--el-color-primary);
  53. }
  54. }
  55. }
  56. </style>