mixin.js 423 B

123456789101112131415161718192021222324
  1. import {
  2. useChatStore
  3. } from '@/store/modules/chat'
  4. export default {
  5. onShow() {
  6. this.setTabBarBadge()
  7. },
  8. methods: {
  9. setTabBarBadge() {
  10. const chatStore = useChatStore()
  11. const badgeNum = chatStore.getBadgeNum || 0
  12. if (badgeNum) {
  13. uni.setTabBarBadge({
  14. index: 3,
  15. text: badgeNum > 99 ? '99+' : badgeNum.toString()
  16. });
  17. } else {
  18. uni.removeTabBarBadge({
  19. index: 3
  20. });
  21. }
  22. }
  23. }
  24. }