desperadojojo
desperadojojo
  • 发布:2020-10-19 21:39
  • 更新:2023-03-20 16:57
  • 阅读:1727

uni.setTabBarBadge 监听事件无效

分类:uni-app

利用uni.setTabBarBadge设置未读消息提醒
// 设置tabBar消息未读提示
alertCount(){
this.$H.get('/alerts-count',{},{token:true}).then(res=>{
console.log(res);
if(res !== 0){
this.alerts_count = String(res);
console.log(this.alerts_count);
this.$nextTick(() => {
uni.setTabBarBadge({
index:3,
text: this.alerts_count
})
})
}
else{
uni.removeTabBarBadge({
index:3
})
}
})
},
onload直接调用上述方法生效。但监听事件时,数据更新了,方法也执行了,但前端就是没有生效。
onLoad() {
// 获取可视区域高度
uni.getSystemInfo({
success: (res) => {
// console.log(res);
this.scrollH = res.windowHeight - 32
}
})
//初始化事件
this.__init(),
this.alertCount(),
uni.$on('alertsCountRefresh',()=>{
console.log('555');
this.alertCount()
})
},
使用$nextTick依然无效,难道uni.setTabBarBadge在监听事件调用时存在bug?

2020-10-19 21:39 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

什么事件无效?

  • 3***@qq.com

    在uni.$on()中设置uni.setTabBarBadge,不起作用

    2020-12-08 15:56

stock2

stock2

是的 在uni.$on() 触发 设置uni.setTabBarBadge,不起作用
只能在 onshow里执行,才有效果.

3***@qq.com

3***@qq.com

that.$nextTick(function(){
uni.removeTabBarBadge({
index: 2

                        })  
                    })

要回复问题请先登录注册