【零基础学会uniapp】第六课:底部tabbar的使用

【零基础学会uniapp】第六课:底部tabbar的使用

6、 底部tabbar的使用

如果应用是一个多 tab 应用,可以通过 tabBar 配置项指定一级导航栏,以及 tab 切换时显示的对应页。

如果需要使用原生的tabbar,则需要在pages.json中进行配置:

建议使用原生tabbar进行开发,非原生的tabbar可能会有卡顿和延迟
在 pages.json 中提供 tabBar 配置,不仅仅是为了方便快速开发导航,更重要的是在App和小程序端提升性能。在这两个平台,底层原生引擎在启动时无需等待js引擎初始化,即可直接读取 pages.json 中配置的 tabBar 信息,渲染原生tab。

tabbar 的页面展现过一次后就保留在内存中,再次切换 tabbar 页面,只会触发每个页面的onShow,不会再触发onLoad。

参数类型必填默认值说明平台差异说明
colorHexColortab 上的文字默认颜色
selectedColorHexColortab 上的文字选中时的颜色
backgroundColorHexColortab 的背景色
borderStyleStringblacktabbar 上边框的颜色,可选值 black/whiteApp 2.3.4+ 支持其他颜色值、H5 3.0.0+
blurEffectStringnoneiOS 高斯模糊效果,可选值 dark/extralight/light/none(参考:使用说明)App 2.4.0+ 支持、H5 3.0.0+(只有最新版浏览器才支持)
listArraytab 的列表,详见 list 属性说明,最少2个、最多5个 tab
positionStringbottom可选值 bottom、toptop 值仅微信小程序支持
fontSizeString10px文字默认大小App 2.3.4+、H5 3.0.0+
iconWidthString24px图标默认宽度(高度等比例缩放)App 2.3.4+、H5 3.0.0+
spacingString3px图标和文字的间距App 2.3.4+、H5 3.0.0+
heightString50pxtabBar 默认高度App 2.3.4+、H5 3.0.0+
midButtonObject中间按钮 仅在 list 项为偶数时有效App 2.3.4+、H5 3.0.0+

其中 list 接收一个数组,数组中的每个项都是一个对象,其属性值如下:

属性类型必填说明
pagePathString页面路径,必须在 pages 中先定义
textStringtab 上按钮文字,在 App 和 H5 平台为非必填。例如中间可放一个没有文字的+号图标
iconPathString图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px,当 position 为 top 时,此参数无效,不支持网络图片,不支持字体图标
selectedIconPathString选中时的图片路径,icon 大小限制为40kb,建议尺寸为 81px * 81px ,当 position 为 top 时,此参数无效

midButton 属性说明

属性 类型 必填 默认值 描述

属性类型必填默认值描述
widthString80px中间按钮的宽度,tabBar 其它项为减去此宽度后平分,默认值为与其它项平分宽度
heightString50px中间按钮的高度,可以大于 tabBar 高度,达到中间凸起的效果
textString中间按钮的文字
iconPathString中间按钮的图片路径
iconWidthString24px图片宽度(高度等比例缩放)
backgroundImageString中间按钮的背景图片路径
"tabBar": {
        "color": "#8A8A8A",
        "selectedColor": "#0081ff",
        "borderStyle": "#EEEEEE",
        "backgroundColor": "#F8F8F8",
        "list": [ {
                "pagePath": "pages/index/index",
                "iconPath": "static/index.png",
                "selectedIconPath": "static/index_select.png",
                "text": "概况"
            },
            {
                "pagePath": "pages/user/user",
                "iconPath": "static/user.png",
                "selectedIconPath": "static/user_select.png",
                "text": "用户"
            }
        ],
        "midButton": {
            "height": "60px",
            "iconPath": "static/add.png",
            "text": "添加"
        }
    }

本课引用链接:

  • 阿里巴巴矢量图标库:https://www.iconfont.cn/
  • 注意事项:https://uniapp.dcloud.io/collocation/pages?id=tips-tabbar
  • 更多tabbar操作: https://uniapp.dcloud.io/api/ui/tabbar?id=settabbaritem
  • 可参考官方例程: 新建-项目-uni-app-底部选项卡模板
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
UniApp 是一个使用 Vue.js 开发跨平台应用的前端框架,它支持将代码一次编写,即可发布到多个平台,包括微信小程序。在 UniApp 中,自定义底部 tabbar 非常简单,只需要在 pages.json 中指定 tabBar 配置,然后在页面中使用自己的自定义 tabbar 组件即可。 以下是自定义底部 tabbar 的步骤: 1. 在 pages.json 文件中设置 tabBar 配置,如下所示: ```javascript { "tabBar": { "custom": true, // 使用自定义的tabBar "color": "#7A7E83", "selectedColor": "#3cc51f", "backgroundColor": "#ffffff", "borderStyle": "white", "list": [ { "pagePath": "pages/index/index", "text": "首页", "iconPath": "/static/tabbar/home.png", "selectedIconPath": "/static/tabbar/home-active.png" }, { "pagePath": "pages/user/user", "text": "我的", "iconPath": "/static/tabbar/user.png", "selectedIconPath": "/static/tabbar/user-active.png" } ] } } ``` 2. 在页面中引入自己的自定义 tabbar 组件,并使用该组件替换默认的 tabBar,如下所示: ```javascript <template> <view> <router-view /> <my-tab-bar :list="list" :active.sync="active" /> </view> </template> <script> import MyTabBar from '@/components/MyTabBar.vue' export default { components: { MyTabBar }, data () { return { active: 0, list: [ { text: '首页', icon: '/static/tabbar/home.png', selectedIcon: '/static/tabbar/home-active.png', path: '/pages/index/index' }, { text: '我的', icon: '/static/tabbar/user.png', selectedIcon: '/static/tabbar/user-active.png', path: '/pages/user/user' } ] } } } </script> ``` 以上是自定义底部 tabbar 的简单介绍,如果您需要更详细的内容,请查看 UniApp 的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jysf98746

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值