tabBar4.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="tabBar">
  3. <view
  4. v-for="(item,index) in tabBar"
  5. :key="item.url"
  6. class="tabbar_item"
  7. :class="{'active':item.url == currentPage}"
  8. @click="navTo(item)"
  9. >
  10. <image v-if="item.url == currentPage" :src="item.imgClick" mode=""></image>
  11. <image v-else :src="item.imgNormal" mode=""></image>
  12. <view class="text">{{item.text}}</view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props:{
  19. currentPage:{
  20. type:String,
  21. default:'index'
  22. }
  23. },
  24. data() {
  25. return {
  26. tabBar:[{
  27. url:'index',
  28. text:'短模板',
  29. imgNormal:'../static/index_change.png',
  30. imgClick:'../static/index.png'
  31. },
  32. {
  33. url:'longIndex',
  34. text:'长模板',
  35. imgNormal:'../static/index_change.png',
  36. imgClick:'../static/index.png'
  37. },{
  38. url:'other',
  39. text:'其他示例',
  40. imgNormal:'../static/index_change.png',
  41. imgClick:'../static/index.png'
  42. }]
  43. };
  44. },
  45. created() {
  46. uni.hideTabBar({})
  47. },
  48. computed:{
  49. },
  50. methods:{
  51. navTo(item){
  52. if(item.url !== this.currentPage){
  53. var isUrl = `/pages/${item.url}/${item.url}`
  54. const that = this
  55. uni.switchTab({
  56. url: isUrl
  57. })
  58. } else{
  59. this.$parent.toTop()
  60. }
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. //导航栏设置
  67. $isRadius:0upx; //左上右上圆角
  68. $isWidth:100vw; //导航栏宽度
  69. $isBorder:0px solid white; //边框 不需要则设为0px
  70. $isBg:white; //背景
  71. // 选中设置
  72. $chooseTextColor:#50B7EA; //选中时字体颜色
  73. $chooseBgColor:transparent; //选中时背景颜色 transparent为透明
  74. //未选中设置
  75. $normalTextColor:#999; //未选中颜色
  76. .tabBar{
  77. width: $isWidth;
  78. height: 100upx;
  79. position: fixed;
  80. bottom: 0;
  81. left: 0;
  82. right: 0;
  83. box-shadow: 0upx -2upx 10upx rgba(89,125,172,.4);
  84. margin:0 auto;
  85. z-index: 998;
  86. background-color: $isBg;
  87. color: $normalTextColor;
  88. border-left: $isBorder;
  89. border-top: $isBorder;
  90. border-right: $isBorder;
  91. display: flex;
  92. justify-content: space-around;
  93. border-top-right-radius: $isRadius;
  94. border-top-left-radius: $isRadius;
  95. box-sizing: border-box;
  96. overflow: hidden;
  97. .tabbar_item{
  98. width: 25%;
  99. font-size: 12px;
  100. display: flex;
  101. flex-direction: column;
  102. justify-content: center;
  103. align-items: center;
  104. &.active{
  105. border-left: $isBorder;
  106. border-top: $isBorder;
  107. background: $chooseBgColor;
  108. color: $chooseTextColor;
  109. }
  110. }
  111. image{
  112. width: 48upx;
  113. height:48upx;
  114. margin-left: 5upx;
  115. }
  116. }
  117. </style>