chat.vue 848 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <view class="tab-page">
  3. <scroll-view class="scroll-bar" scroll-with-animation="true" scroll-y="true">
  4. <view v-for="(chat,index) in $store.state.chatStore.chats" :key="index">
  5. <chat-item :chat="chat" :index="index"></chat-item>
  6. </view>
  7. </scroll-view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. }
  15. },
  16. methods: {
  17. refreshUnreadBadge(){
  18. if(this.unreadCount>0){
  19. uni.setTabBarBadge({
  20. index: 0,
  21. text: this.unreadCount+""
  22. })
  23. }else{
  24. uni.removeTabBarBadge({
  25. index:0
  26. })
  27. }
  28. }
  29. },
  30. computed:{
  31. unreadCount(){
  32. let count = 0;
  33. this.$store.state.chatStore.chats.forEach(chat =>{
  34. count += chat.unreadCount;
  35. })
  36. return count;
  37. }
  38. },
  39. onLoad() {
  40. this.refreshUnreadBadge();
  41. }
  42. }
  43. </script>
  44. <style>
  45. </style>