graceNvueNavBar.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <scroll-view scroll-with-animation
  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, fontWeight:currentIndex == index ? activeFontWeight : ''}">{{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. activeFontWeight: {type : Number, default : 700},
  34. margin : {type : Number, default : 0},
  35. textAlign : {type : String, default : 'left'},
  36. lineHeight :{type : String, default : '50rpx'},
  37. padding : {type : String, default : '0rpx'},
  38. activeLineRadius : {type : String, default : "0rpx"}
  39. },
  40. methods:{
  41. navchang : function (e){
  42. this.$emit('change', Number(e.currentTarget.dataset.index))
  43. }
  44. }
  45. }
  46. </script>
  47. <style scoped>
  48. .grace-nav-bar{flex-direction:row;}
  49. .nav-item{flex-direction:column;}
  50. .nav-item-title{width:100%; color:#333333;}
  51. .nav-active{}
  52. .nav-active-line-wrap{flex-direction:row;}
  53. .nav-active-line{margin-top:5rpx;}
  54. .grace-nav-center{justify-content:center; text-align:center;}
  55. </style>