tabBar 是移动应用中常见的导航模式,uni-app 提供了丰富的 API 来动态控制 tabBar 的外观和行为。
1. uni.setTabBarItem(object)
动态设置 tabBar 某一项的内容
参数说明
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
tabBar 是移动应用中常见的导航模式,uni-app 提供了丰富的 API 来动态控制 tabBar 的外观和行为。 1\. uni.setTabBarItem(object) 动态设置 tabBar 某一项的内容 参数说明 | 属性 | 类型 | 默认值 | 必填 | 说明 | | --- | --- | --- | --- | --- | | index | number | | 是 |…
tabBar 是移动应用中常见的导航模式,uni-app 提供了丰富的 API 来动态控制 tabBar 的外观和行为。
动态设置 tabBar 某一项的内容
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
text |
| string |
| 否 |
| tab 上的按钮文字 |
iconPath | string | 否 | 图片路径,icon 大小限制为 40kb |
selectedIconPath | string | 否 | 选中时的图片路径,icon 大小限制为 40kb |
success | function | 否 | 接口调用成功的回调函数 |
fail | function | 否 | 接口调用失败的回调函数 |
complete | function | 否 | 接口调用结束的回调函数 |
uni.setTabBarItem({index:0,text:"首页",iconPath:"/static/icon/home.png",selectedIconPath:"/static/icon/home-active.png",});
动态设置 tabBar 的整体样式
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
color | string | 否 | tab 上的文字默认颜色 | |
selectedColor | string | 否 | tab 上的文字选中时的颜色 | |
backgroundColor | string | 否 | tab 的背景色 | |
borderStyle | string | 否 | tabBar 上边框的颜色,仅支持 black/white | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
uni.setTabBarStyle({color:"#7A7E83",selectedColor:"#007AFF",backgroundColor:"#F8F8F8",borderStyle:"black",});
隐藏 tabBar
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
animation | boolean | false | 否 | 是否需要动画效果 |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 隐藏 tabBar,带动画效果 uni.hideTabBar({animation:true,});
显示 tabBar
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
animation | boolean | false | 否 | 是否需要动画效果 |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 显示 tabBar,带动画效果 uni.showTabBar({animation:true,});
为 tabBar 某一项右上角添加文本
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
text | string | 是 | 显示的文本,超过 4 个字符则显示为 … | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 为第一个 tab 添加 badge uni.setTabBarBadge({index:0,text:"3",});
移除 tabBar 某一项右上角的文本
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 移除第一个 tab 的 badge uni.removeTabBarBadge({index:0,});
显示 tabBar 某一项的右上角红点
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 显示第一个 tab 的红点 uni.showTabBarRedDot({index:0,});
隐藏 tabBar 某一项的右上角红点
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
index | number | 是 | tabBar 的哪一项,从左边算起 | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数 |
// 隐藏第一个 tab 的红点 uni.hideTabBarRedDot({index:0,});
exportdefault{methods:{// 初始化 tabBar 样式initTabBar(){// 设置 tabBar 整体样式 uni.setTabBarStyle({color:"#7A7E83",selectedColor:"#007AFF",backgroundColor:"#FFFFFF",borderStyle:"black",});// 设置各 tab 项 uni.setTabBarItem({index:0,text:"首页",iconPath:"/static/tabbar/home.png",selectedIconPath:"/static/tabbar/home-selected.png",}); uni.setTabBarItem({index:1,text:"分类",iconPath:"/static/tabbar/category.png",selectedIconPath:"/static/tabbar/category-selected.png",}); uni.setTabBarItem({index:2,text:"购物车",iconPath:"/static/tabbar/cart.png",selectedIconPath:"/static/tabbar/cart-selected.png",}); uni.setTabBarItem({index:3,text:"我的",iconPath:"/static/tabbar/user.png",selectedIconPath:"/static/tabbar/user-selected.png",});},// 更新购物车数量显示updateCartBadge(count){if(count >0){ uni.setTabBarBadge({index:2,text: count.toString(),});}else{ uni.removeTabBarBadge({index:2,});}},// 显示消息红点showMessageDot(show){if(show){ uni.showTabBarRedDot({index:3,});}else{ uni.hideTabBarRedDot({index:3,});}},// 在特定页面隐藏 tabBarhideTabBarInPage(){ uni.hideTabBar({animation:true,});},// 返回页面时显示 tabBarshowTabBarInPage(){ uni.showTabBar({animation:true,});},},mounted(){this.initTabBar();},};
iconPath 和 selectedIconPath 必须使用本地资源路径
微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
解析常见 curl 参数并生成 fetch、axios、PHP curl 或 Python requests 示例代码。 在线工具,curl 转代码在线工具,online
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online