微信小程序/uniapp动态修改tabBar信息及常见报错

目录

uni.setTabBarItem(options)

介绍:

wx.setTabBarItem是不支持修改url路径的,所以使用uniapp的API。

动态设置 tabBar 某一项的内容:uniapp官网

setTabBarItem 兼容性:

Web Android iOS
4.0 3.91 4.11

参数:

options里的具体参数:

名称 类型 必备 默认值 兼容性 描述
index number 是 - - tabBar 的哪一项,从左边算起,索引从0开始
text string 否 - - tab 上按钮文字
iconPath string 否 - - 图片路径
selectedIconPath string 否 - - 选中时的图片路径
pagePath string 否 - - 页面绝对路径
iconfont SetTabBarItemIconFontOptions 否 - - 字体图标,优先级高于 iconPath
visible boolean 否 - - tab 是否显示
success (result: AsyncApiSuccessResult) => void 否 - - 接口调用成功的回调函数
fail (result: SetTabBarFail) => void 否 - - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void 否 - - 接口调用结束的回调函数(调用成功、失败都会执行)

iconfont 包含参数:

名称 类型 必备 默认值 兼容性 描述
text string 是 - - 字库 Unicode 码
selectedText string 是 - - 选中后字库 Unicode 码
fontSize string 否 - - 字体图标字号(px)
color string 否 - - 字体图标颜色
selectedColor string 否 - - 字体图标选中颜色

示例:

javascript 复制代码
uni.setTabBarItem({
  index: 0,
  text: 'text',
  iconPath: '/path/to/iconPath',
  selectedIconPath: '/path/to/selectedIconPath',
  pagePath: '/path/newPagePath',
  success: ()=>{
    console.log('success');
  },
  fail: ()=>{
    console.log('success');
  },
  complete: ()=>{
    console.log('success');
  },
})

报错

使用时遇到了报错:"setTabBarItem:fail not TabBar page"

原因:setTabBarItem方法 只能在tabbar页面调用(有看到有人说在app中可以在非tabbar页面调用,但是我只是在微信小程序中使用,所以不清楚能不能用)

解决方法:在tabBar页面调用(没办法,微信小程序不支持)

相关推荐
qq_3168377513 小时前
阿里云百炼 fun-asr-realtime uniapp vue3 调用
javascript·vue.js·uni-app
m0_4628038813 小时前
会议签到里,手写签名怎样从“额外动作“变成流程环节
微信小程序
醒目8019 小时前
从图像到拼豆图纸:像素化生成与色板匹配技术实践
微信小程序
特创数字科技19 小时前
uniapp 图片全能处理|全平台支持(鸿蒙、安卓、苹果、web),实现九宫格、水印、滤镜、压缩、拼图
uni-app
2501_9160074720 小时前
苹果应用商店App Store上架费用标准及原因解析
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张2 天前
苹果App Store上架指南:费用、原理与步骤详解
android·ios·小程序·https·uni-app·iphone·webview
特创数字科技2 天前
【uni-app x】告别系统相机限制!三端通用自定义相机组件:任意布局、静默拍照、录像、水印叠加、连拍回图一次搞定
前端·数码相机·uni-app
Martin -Tang2 天前
uniapp app嵌套webview 弹窗方式
android·ios·uni-app
愚公搬代码2 天前
【愚公系列】《微信小程序项目实战(AI编程+视频图解)》002-一张新地图:AI创业的核心分析框架
人工智能·微信小程序·ai编程
ZeroNews内网穿透2 天前
企业内网穿透别再用随机域名!自有域名实现 OA/ERP 公网安全访问
微信小程序·内网穿透·erp·zeronews·运维实战·企业oa·自有域名