graceNavBar.nvue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <scroll-view
  3. :class="['grace-nav-bar', isCenter ? 'grace-nav-center' : '']" :scroll-x="true"
  4. :scroll-into-view="'tab-'+currentIndex" :show-scrollbar="false">
  5. <view class="nav-item" :id="'tab-'+index"
  6. :style="{width:size+'rpx', marginRight:margin+'rpx', padding:'0rpx '+padding}"
  7. v-for="(item, index) in items" :key="index" @click="navchang" :data-index="index">
  8. <text :class="['nav-item-title', currentIndex == index ? 'nav-active' : '']"
  9. :style="{color:currentIndex == index ? activeColor:color, width:size+'rpx', lineHeight:lineHeight, fontSize:currentIndex == index ? activeFontSize : fontSize, textAlign:textAlign}">{{item}}</text>
  10. <view class="nav-active-line-wrap" :style="{justifyContent:activeDirection}">
  11. <view class="nav-active-line"
  12. :style="{backgroundImage:activeLineBg, width:activeLineWidth, height:activeLineHeight, borderRadius:activeLineRadius}"
  13. v-if="currentIndex == index"></view>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. </template>
  18. <script>
  19. export default {
  20. props:{
  21. isCenter : {type : Boolean, default : false},
  22. currentIndex : {type : Number,default : 0},
  23. size : {type : Number, default : 120},
  24. fontSize : {type : String,default : '28rpx'},
  25. activeFontSize : {type : String, default : '28rpx'},
  26. items : {type : Array,default : function () {return []}},
  27. activeLineBg : {type : String, default : "linear-gradient(to right, #66BFFF,#3388FF)"},
  28. color : {type : String, default : "#333333"},
  29. activeColor:{type : String, default : "#333333"},
  30. activeLineHeight : {type : String, default : '6rpx'},
  31. activeLineWidth : {type : String, default : "36rpx"},
  32. activeDirection : {type : String, default : ""},
  33. margin : {type : Number, default : 0},
  34. textAlign : {type : String, default : 'left'},
  35. lineHeight :{type : String, default : '50rpx'},
  36. padding : {type : String, default : '0rpx'},
  37. activeLineRadius : {type : String, default : "0rpx"}
  38. },
  39. methods:{
  40. navchang : function (e){
  41. this.$emit('change', Number(e.currentTarget.dataset.index))
  42. }
  43. }
  44. }
  45. </script>
  46. <style scoped>
  47. .grace-nav-bar{flex-direction:row;}
  48. .nav-item{flex-direction:column;}
  49. .nav-item-title{width:100%; color:#333333;}
  50. .nav-active{font-weight:900;}
  51. .nav-active-line-wrap{flex-direction:row;}
  52. .nav-active-line{margin-top:5rpx;}
  53. .grace-nav-center{justify-content:center; text-align:center;}
  54. </style>