myTabs.vue 1.4 KB

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