• 使用uniapp开发时自定义tabbar


    预览图:

     一、配置page.jsong中的tabbar(这一步是必须的,因为我们在使用uni.switchTab()时必须要用到)

    1. "tabBar": {
    2. "list": [{
    3. "pagePath": "pages/index/index",
    4. "iconPath": "static/images/icon/home.png",
    5. "selectedIconPath": "static/images/icon/home_select.png",
    6. "text": "首页"
    7. }, {
    8. "pagePath": "pages/OldGoods/OldGoods",
    9. "iconPath": "static/images/icon/home.png",
    10. "selectedIconPath": "static/images/icon/home_select.png",
    11. "text": "二手"
    12. },{
    13. "pagePath": "pages/list/list",
    14. "iconPath": "",
    15. "selectedIconPath": "",
    16. "text": "权益"
    17. },{
    18. "pagePath": "pages/IntegralMall/IntegralMall",
    19. "iconPath": "",
    20. "selectedIconPath": "",
    21. "text": "积分商城"
    22. },{
    23. "pagePath": "pages/me/me",
    24. "iconPath": "static/images/icon/me.png",
    25. "selectedIconPath": "static/images/icon/me_select.png",
    26. "text": "我的"
    27. }]
    28. }

    二、编写tabbar组件

    view:
    1. <view class="tab-bar">
    2. <view class="center-btn-box">
    3. <view class="center-btn" @click="SwitchTab('/pages/list/list',2)">
    4. <image class="center-icon" src="../../static/images/label/cent_btn.png">image>
    5. view>
    6. view>
    7. <view class="tab-list">
    8. <view :class="['tab-item',pageindex===index?'action':'']" v-for="(item,index) in list" @click="SwitchTab(item.path,index)">
    9. <view class="tab-icon">
    10. <image :src="pageindex===index?item.iconAction:item.icon" class="icon">image>
    11. view>
    12. <view class="tab-name">{{item.title}}view>
    13. view>
    14. view>
    15. view>
    css:这里就省略了,我中间那个其实就是用一个元素把中间那个选项给遮挡住,点击时使用uni.switchTab()仅此而已
    js:我这里使用props属性的方式传值,因为点击时要做页面状态的切换,
    1. props:{
    2. pageindex:Number
    3. },
    4. name:"TabBar",
    5. data() {
    6. return {
    7. list:[
    8. {
    9. title:"首页",
    10. icon:"../../static/images/label/tab_sy_01.png",
    11. iconAction:"../../static/images/label/tab_sy_02.png",
    12. path:"/pages/index/index?id=0"
    13. },
    14. {
    15. title:"二手",
    16. icon:"../../static/images/label/tab_es_01.png",
    17. iconAction:"../../static/images/label/tab_es_02.png",
    18. path:"/pages/OldGoods/OldGoods"
    19. },{
    20. title:"权益",
    21. icon:"../../static/images/label/tab_qy_01.png",
    22. iconAction:"../../static/images/label/tab_qy_02.png",
    23. path:"/pages/list/list"
    24. },{
    25. title:"积分商城",
    26. icon:"../../static/images/label/tab_jf_01.png",
    27. iconAction:"../../static/images/label/tab_jf_02.png",
    28. path:"/pages/IntegralMall/IntegralMall"
    29. },{
    30. title:"我的",
    31. icon:"../../static/images/label/tab_wd_01.png",
    32. iconAction:"../../static/images/label/tab_wd_02.png",
    33. path:"/pages/me/me"
    34. }
    35. ]
    36. };
    37. },
    使用组件:
    1. <template>
    2. <TabBar :pageindex="0">TabBar>
    3. template>
    4. <script>
    5. import TabBar from "@/components/TabBar/TabBar.vue"
    6. export default {
    7. components:{
    8. TabBar
    9. }
    10. }
    11. script>

  • 相关阅读:
    LVS负载均衡群集
    bean生命周期
    STL中map容器详解,对组类型的简单剖析。
    二叉树根节点到叶子节点的所有路径和
    测试开发面试题
    基于STM32+华为云IOT设计的智能车库管理系统
    如何写论文
    k8s 实战 常见异常事件 event 及解决方案分享
    基于opengauss数据库的酒水销售管理系统
    校招|拿到腾讯、阿里、字节等10家互联网测试开发岗的offer
  • 原文地址:https://blog.csdn.net/qq_40128591/article/details/136352363