tabs-view.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!-- 注意:此tab-view仅为z-paging的demo演示之用,未作兼容与细节处理,不建议直接使用,建议使用第三方成熟的tab-view -->
  2. <template name="tabs-view">
  3. <view class="segment">
  4. <view class="segment-item" v-for="(title,index) in items" :key="index" :style="{width:itemWidth}" @click="itemClick(index)">
  5. <view class="title-container">
  6. <text class="title" :style="{color:currentIndex===index?'#007AFF':'darkgray'}">{{title}}</text>
  7. </view>
  8. <view class="line" v-if="currentIndex===index"></view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: 'tabs-view',
  15. data() {
  16. return {
  17. currentIndex: 0
  18. };
  19. },
  20. props: {
  21. items: {
  22. type: Array,
  23. default: function() {
  24. return [];
  25. }
  26. },
  27. current: {
  28. type: Number,
  29. default: function() {
  30. return 0;
  31. }
  32. }
  33. },
  34. watch: {
  35. current(newVal){
  36. this.currentIndex = newVal;
  37. }
  38. },
  39. computed: {
  40. itemWidth() {
  41. // #ifdef APP-NVUE
  42. return (750 / this.items.length) + 'rpx';
  43. // #endif
  44. // #ifndef APP-NVUE
  45. return ((1.0 / this.items.length) * 100) + '%';
  46. // #endif
  47. }
  48. },
  49. methods: {
  50. itemClick(index) {
  51. if (this.currentIndex != index) {
  52. this.$emit('change', index);
  53. }
  54. this.currentIndex = index;
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. .segment-control {}
  61. .segment {
  62. background-color: white;
  63. height: 80rpx;
  64. /* #ifndef APP-NVUE */
  65. display: flex;
  66. /* #endif */
  67. flex-direction: row;
  68. font-size: 30rpx;
  69. color: darkgray;
  70. border-bottom: #eeeeee solid 1px;
  71. z-index: 1000;
  72. }
  73. .segment-item {
  74. height: 80rpx;
  75. /* #ifndef APP-NVUE */
  76. display: flex;
  77. /* #endif */
  78. flex-direction: column;
  79. align-items: center;
  80. justify-content: center;
  81. }
  82. .title-container {
  83. width: 100%;
  84. height: 76rpx;
  85. /* #ifndef APP-NVUE */
  86. display: flex;
  87. /* #endif */
  88. justify-content: center;
  89. align-items: center;
  90. text-align: center;
  91. }
  92. .title {
  93. width: 100%;
  94. font-size: 30rpx;
  95. text-align: center;
  96. }
  97. .line {
  98. height: 2px;
  99. width: 70%;
  100. background-color: #007AFF;
  101. }
  102. </style>