当前位置:   article > 正文

uniapp之简单版本的自定义tab栏切换_uniapptab栏切换

uniapptab栏切换

前言

最开始使用的是uniapp官网里面的 uni-segmented-control 这个属性实现 tab栏切换,但奈何,抵不过业务上的需求,只能 自己手写 tab栏切换

需求是:在某个背景色为黑色的情况下,里面加个tab栏切换,既然背景色为黑色,那字体肯定是要设置为白色的,但,我直接在 组件上设置 color 属性,但奈何它不生效,一气之下只能在组件文件里面更改字体 color 属性,嗯,问题解决了,但,不曾想另一个白色页面也需要设置tab栏切换,

我只能自己找其他组件来实现这个功能,但是呢,我下载另外一个组件,它文档里面是有这个属性,但不知为何会报查找不到文件的错误,最开始,还以为自己引入(npm  i 下载)后,配置不对,最后才发现,自己需要的这个功能真的在文件里找不到,所以只能自己找办法了,

所幸找到了

总代码 

  1. <template>
  2. <view>
  3. <view class="tab_nav">
  4. <view class="navTitle" v-for="(item,index) in navList" :key="index">
  5. <view :class="{'active':current === index}" @click="checked(index)">
  6. {{item.title}}
  7. </view>
  8. </view>
  9. </view>
  10. <view class="nav_item" v-if="current==0">
  11. 0
  12. </view>
  13. <view class="nav_item" v-if="current==1">
  14. 1
  15. </view>
  16. <view class="nav_item" v-if="current==2">
  17. 2
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. current: 0,
  26. navList: [{
  27. index: 0,
  28. title: '进行中'
  29. }, {
  30. index: 1,
  31. title: "未支付"
  32. }, {
  33. index: 2,
  34. title: "已完成"
  35. }]
  36. }
  37. },
  38. methods: {
  39. checked(index) {
  40. this.current = index
  41. },
  42. }
  43. }
  44. </script>
  45. <style lang="scss" scoped>
  46. .tab_nav {
  47. display: flex;
  48. justify-content: center;
  49. align-items: center;
  50. }
  51. .tab_nav .navTitle {
  52. height: 90rpx;
  53. line-height: 90rpx;
  54. width: 100%;
  55. text-align: center;
  56. font-size: 32rpx;
  57. font-family: Alibaba PuHuiTi;
  58. color: #333;
  59. }
  60. .active {
  61. position: relative;
  62. color: #1F75FE;
  63. }
  64. .active::after {
  65. content: "";
  66. position: absolute;
  67. width: 100rpx;
  68. height: 4rpx;
  69. background-color: #1F75FE;
  70. left: 0px;
  71. right: 0px;
  72. bottom: 0px;
  73. margin: auto;
  74. }
  75. </style>

效果图

总结

这段时间,总是在组件上 更改背景色啊,或者是干嘛的,

例如我之前想让 card 卡片的背景色改为其他色 ,但它

总是不生效,那建议大家,先看看那个组件使用的频率或者是看它全局都是某种色,若是的话,则最好时去组件对应的文件里面,看看,看相关的属性进项修改

后续

因下面的代码 在工作中很常用(就样式好看) 就 写下来记录下,等后续使用时直接 CV

.flex {
  display: flex;
}

.justify-between {
  justify-content: space-between
}

最外层view标签   <view class="" style="padding: 82rpx 68rpx 0 74rpx;color:#328fb1">

  1. <view class="flex justify-between">
  2. <view class="scroll-view-item_H" v-for="(item,index) in navList" :key="index">
  3. <view :class="{'active':currentInd === index}" @click="checked(index)">
  4. {{item.title}}
  5. </view>
  6. </view>
  7. </view>
  8. <view class="" v-if="currentInd===0">
  9. 1222
  10. </view>
  11. <view class="" v-if="currentInd===1">
  12. 3412
  13. </view>
  14. data
  15. currentInd: 0,
  16. navList: [{
  17. index: '1',
  18. title: '未完成'
  19. }, {
  20. index: '2',
  21. title: "已完成"
  22. }],
  23. methods :
  24. checked(index) {
  25. this.currentInd = index
  26. },
  27. style 样式
  28. $color : #427cb2;
  29. $fff: #fff;
  30. .scroll-view-item_H {
  31. width: 212rpx;
  32. height: 90rpx;
  33. line-height: 90rpx;
  34. text-align: center;
  35. font-size: 16px;
  36. border-radius: 20rpx;
  37. // margin-right: 38px;
  38. background-color: $fff;
  39. margin-right: 20rpx;
  40. }
  41. .active {
  42. border-radius: 20rpx;
  43. color: $fff;
  44. background-color: $color;
  45. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/963631
推荐阅读
相关标签
  

闽ICP备14008679号