效果

实现
在app.vue中设置
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
this.getUnreadCount()
},
onHide: function() {
console.log('App Hide')
},
methods: {
getUnreadCount() {
// 模拟获取未读消息数
const unreadCount = 10;
// 通过全局变量或Vuex状态管理消息数
// 更新tabbar的badge
uni.setTabBarBadge({
index: 2, // 消息tab的索引,对应pages.json中的index
text: unreadCount > 99 ? '...' : String(unreadCount)
});
}
}
}
</script>