myTabs.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <view :class="{'my-tabs':true,'space-between':formatBe}">
  3. <view v-for="(item,index) in getModelData" :key="index" :class="{'tab-item':true,'active':formatIndex==index}" @tap="tap(index)">
  4. {{item.label}}
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props:['modelData','initIndex'],
  11. data() {
  12. return {
  13. }
  14. },
  15. computed:{
  16. getModelData(){
  17. return this.modelData
  18. },
  19. formatBe(){
  20. return this.modelData
  21. ?this.modelData.length>4?true:false
  22. :false
  23. },
  24. formatIndex(){
  25. return this.initIndex
  26. }
  27. },
  28. methods: {
  29. tap(index){
  30. console.log("我点击了",index);
  31. this.$emit("change",index);
  32. }
  33. }
  34. }
  35. </script>
  36. <style lang='scss'>
  37. .my-tabs {
  38. background-color: #ffffff;
  39. height: 88upx;
  40. font-size: 28upx;
  41. display: flex;
  42. justify-content: space-around;
  43. box-sizing: border-box;
  44. border-top: 2upx solid #dddddd;
  45. border-bottom: 2upx solid #dddddd;
  46. min-width: 100%;
  47. overflow-x: auto;
  48. .tab-item{
  49. line-height: 48upx;
  50. padding: 20upx;
  51. min-width: 100upx;
  52. text-align: center;
  53. }
  54. .tab-item.active{
  55. position: relative;
  56. color: #3682FF;
  57. }
  58. .tab-item.active::after{
  59. content: "";
  60. position: absolute;
  61. bottom: 0;
  62. left:50%;
  63. transform: translateX(-50%);
  64. width: 100%;
  65. border-bottom: 4upx solid #3682FF;
  66. animation: test ease 1 1.5s;
  67. }
  68. }
  69. .my-tabs.space-between{
  70. justify-content: space-between;
  71. }
  72. @keyframes test{
  73. 0%{width: 100%}
  74. 50%{width: 150%}
  75. 100%{width: 100%}
  76. }
  77. </style>