App.vue 858 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <script>
  2. export default {
  3. onLaunch: function () {
  4. const getMessageCount = async () => {
  5. if(!this.$store.state.token) return
  6. try {
  7. let res = await this.$http.get('/message/getMessageCount')
  8. if (res.code == 200 && res.data) {
  9. uni.setTabBarBadge({
  10. index: 2,//tabbar的索引
  11. text: res.data['999'] + ''
  12. })
  13. }
  14. } catch (e) {
  15. // 静默处理:token过期等场景不弹“登录已失效”,由拦截器/登录页统一处理
  16. }
  17. }
  18. setInterval(() => {
  19. getMessageCount()
  20. }, 30000);
  21. },
  22. async onShow() {
  23. },
  24. onHide: function () { }
  25. }
  26. </script>
  27. <style lang="scss">
  28. /* #ifndef APP-PLUS-NVUE */
  29. /*每个页面公共css */
  30. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  31. @import "uview-ui/index.scss";
  32. /* 公共样式库 */
  33. @import "/style/zcm-main.css";
  34. /* #endif */
  35. </style>