myTabs.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. position: sticky;
  43. justify-content: space-around;
  44. box-sizing: border-box;
  45. border-top: 2upx solid #dddddd;
  46. border-bottom: 2upx solid #dddddd;
  47. min-width: 100%;
  48. overflow-x: auto;
  49. .tab-item{
  50. line-height: 48upx;
  51. padding: 20upx;
  52. min-width: 100upx;
  53. text-align: center;
  54. }
  55. .tab-item.active{
  56. position: relative;
  57. color: #3682FF;
  58. }
  59. .tab-item.active::after{
  60. content: "";
  61. position: absolute;
  62. bottom: 0;
  63. left:50%;
  64. transform: translateX(-50%);
  65. width: 100%;
  66. border-bottom: 4upx solid #3682FF;
  67. animation: test ease 1 1.5s;
  68. }
  69. }
  70. .my-tabs.space-between{
  71. justify-content: space-between;
  72. }
  73. @keyframes test{
  74. 0%{width: 100%}
  75. 50%{width: 150%}
  76. 100%{width: 100%}
  77. }
  78. </style>