利用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?
![desperadojojo](https://img-cdn-tc.dcloud.net.cn/account/identicon/4c88c23f0bb042cf76728a8f9bd263f9.png)
desperadojojo
- 发布:2020-10-19 21:39
- 更新:2023-03-20 16:57
- 阅读:2016
3***@qq.com
在uni.$on()中设置uni.setTabBarBadge,不起作用
2020-12-08 15:56