TabSwitcher.vue 933 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div class="tab-switcher">
  3. <div :class="{ active: selectedTab === 'latest' }" @click="selectTab('latest')">
  4. <span style="font-size: 10px">最新</span>
  5. </div>
  6. <div :class="{ active: selectedTab === 'hot' }" @click="selectTab('hot')">
  7. <span style="font-size: 10px">热门</span>
  8. </div>
  9. </div>
  10. </template>
  11. <script setup>
  12. import { ref } from 'vue'
  13. const emit = defineEmits(['selectTab'])
  14. const selectedTab = ref('latest')
  15. const selectTab = (tab) => {
  16. if (selectedTab.value != tab) {
  17. selectedTab.value = tab
  18. emit('selectTab', tab)
  19. }
  20. }
  21. </script>
  22. <style scoped>
  23. .tab-switcher {
  24. display: flex;
  25. border-radius: 20px;
  26. border: 1px solid #1e90ff;
  27. overflow: hidden;
  28. }
  29. .tab-switcher div {
  30. padding: 1px 15px;
  31. background-color: #f5f5f5;
  32. cursor: pointer;
  33. }
  34. .tab-switcher div.active {
  35. background-color: #1e90ff;
  36. color: white;
  37. }
  38. .tab-switcher div:not(:last-child) {
  39. }
  40. </style>