tabs.vue 824 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <div class="btn-group">
  3. <div
  4. :class="['btn-item', { active: active === index }]"
  5. @click="handleActive(index)"
  6. v-for="(item, index) in list"
  7. :key="index"
  8. >
  9. {{ item }}
  10. </div>
  11. </div>
  12. </template>
  13. <script setup>
  14. import {ref} from 'vue'
  15. const props = defineProps({
  16. list: {
  17. type: Array,
  18. defalut: [],
  19. },
  20. });
  21. const active = ref(0);
  22. const handleActive = (i) => {
  23. active.value = i;
  24. };
  25. </script>
  26. <style lang="scss" scoped>
  27. .btn-group {
  28. font-size: 11px;
  29. display: flex;
  30. align-items: center;
  31. .btn-item {
  32. border-radius: 2px;
  33. padding: 3px 8px;
  34. margin-left: 8px;
  35. cursor: pointer;
  36. &.active {
  37. background: #4f4f4f;
  38. }
  39. }
  40. }
  41. </style>