实现同步未读消息条数

在这里插入图片描述
需求描述: 模块内的未读信息被读后,头部的未读信息条数要跟着变动。

//home
  <div @click="handleMessage">
          <el-badge
            v-if="messageData.length != 0"
            :value="messageData.length"
            :max="99"
            :class="messageData.length <= 99 ? 'badge' : 'other'"
          >
            <i class="el-icon-message-solid icon main-color"></i>
          </el-badge>
          <div v-else class="all-massage">
            <i class="el-icon-message-solid main-color"></i>
          </div>
  </div>

关键操作:在utils.js里面设置window添加时间

//window下添加时间,通知信息数量变化
const EVENT_MESSAGENUM = "EVENT_MESSAGENUM";
//home
  created() {
    let _this = this;
    this.getMenu();
    this.queryCount();
    window[utils.EVENT_MESSAGENUM] = function() {
      _this.queryCount();
    };
  },
  method(){
      // 获取铃铛未读消息数量
    queryCount() {
      messageList().then(res => {
        // console.log(res,'头部请求')
        if (res.data.code == 200) {
          let messageAll = res.data.data.list;
          this.messageData = messageAll.filter(e => {
            return e.readed == 1;
          });
        }
      });
    }
  }

关键操作: 在标记已读的时候,触发window事件

    // 标记全部为已读
    toMarkRead() {
      this.http
        .post(`${this.interfacePrefix}markAllMessageAsReaded`)
        .then(res => {
          if (res.data.code == 200) {
            window.top[utils.EVENT_MESSAGENUM]();
            this.$message.success(res.data.msg);
            this.handleFilter();
          }
        });
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值