1-1 tab切换

  1. <template>
  2. <div>
  3. <div>
  4. <div class="tabs-box">
  5. <div
  6. @click="handleItem(index)"
  7. v-for="(item, index) of items"
  8. :key="index"
  9. :class="['tabs-item', currentIndex == index ? 'selected' : '']"
  10. >
  11. {{ item }}
  12. </div>
  13. </div>
  14. <div class="product-detail-box">
  15. <div v-show="currentIndex==0">detail</div>
  16. <div v-show="currentIndex==1">param</div>
  17. <div v-show="currentIndex==2">sale</div>
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. items: ["选项一", "选项二", "选项三"],
  27. currentIndex: 0,
  28. };
  29. },
  30. methods: {
  31. handleItem(index) {
  32. this.currentIndex = index;
  33. },
  34. },
  35. };
  36. </script>
  37. <style scoped>
  38. .selected {
  39. color: rgba(171, 149, 109, 0.8);
  40. border-bottom: 2px solid rgba(171, 149, 109, 0.8);
  41. }
  42. .tabs-box {
  43. display: flex;
  44. height: 50rpx;
  45. }
  46. .tabs-item {
  47. flex: 1;
  48. text-align: center;
  49. }
  50. </style>