UNIAPP原生TABBAR设置并添加数字角标或小红点提示


uni.setTabBarBadge({ //显示数字
  index: 2,//tabbar下标
  text: '1'//数字
})
uni.removeTabBarBadge({ //隐藏数字标
  index:2
})  
uni.showTabBarRedDot({ //显示红点
  index: 2
})
uni.hideTabBarRedDot({ //隐藏红点
  index:2
})
添加至任何页面的js事件里即可,事件执行,则显示或移除
详情可以看官网地址https://uniapp.dcloud.io/api/ui/tabbar?id=showtabbarreddot
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp中,可以通过以下步骤在TabBar添加角标: 1. 在App.vue中定义一个计算属性,用于获取需要显示角标的数量: ``` computed: { badgeCount() { return this.$store.state.badgeCount; } } ``` 2. 在TabBar.vue中,使用uni-icons组件添加角标图标,并根据计算属性的值控制角标是否显示: ``` <template> <view> <view class="tabbar"> <view v-for="(item, index) in tabbarList" :key="index" class="tabbar-item" :class="currentIndex === index ? 'active' : ''" @click="changeTabbar(index)" > <view class="icon"> <uni-icons :type="item.icon" size="24"></uni-icons> <!-- 添加角标 --> <view v-if="index === 2 && badgeCount > 0" class="badge">{{badgeCount}}</view> </view> <view class="title">{{item.text}}</view> </view> </view> </view> </template> <style> .badge { position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; background-color: red; color: #fff; font-size: 12px; border-radius: 50%; display: flex; align-items: center; justify-content: center; } </style> ``` 在这个例子中,我们假设需要在第三个Tab上添加角标,并且角标的数量通过Vuex状态管理实现。当badgeCount的值大于0时,角标会显示出来。 3. 在Vuex中定义state和mutations用于管理角标数量: ``` const store = new Vuex.Store({ state: { badgeCount: 0 }, mutations: { increment(state) { state.badgeCount++; }, decrement(state) { state.badgeCount--; } } }); ``` 4. 在需要更新角标数量的地方,调用Vuex的mutations方法更新状态: ``` this.$store.commit('increment'); ``` 这样,在TabBar上就可以动态地显示角标了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值