基于vue2.x实现的即时通讯程序仿微信聊天11细节优化01

2022-12-03  本文已影响0人  风中凌乱的男子
image.png
.avatar {
   ::v-deep img {
     filter: grayscale(100%);
   }
}
image.png
image.png
 :class="(index==0?'color':'')"
 .color{
          ::v-deep img {
            filter: grayscale(0%);
          }
        }
image.png
image.png
 sockets: {
    users: function (data) {
      console.log(data)
    },
  },
image.png
sockets: {
    users: function (data) {
      console.log(data)
      console.log(Object.keys(data))
    }
  },
image.png
:class="item.isZaixian == 1 ? 'color' : ''"
 sockets: {
    users: function (data) {
      console.log(data)
      console.log(Object.keys(data))
      this.isZaixianArr = Object.keys(data)
    }
  },

 data() {
    return {
        isZaixianArr:[]
    }
}
async getMyfriendsFun() {
      try {
        const res = await getMyfriends()
        let arr = res.data
        const idSet = new Set(this.isZaixianArr)
        //https://blog.csdn.net/yiyueqinghui/article/details/107773347
        const res1 = arr.map(o => ({ ...o, isZaixian: idSet.has(o._id) ? 1 : o.isZaixian }))
        this.list = res1
      } catch (error) {
        console.log(error)
      }
    },
sockets: {
    users: function (data) {
      // console.log(data)
      // console.log(Object.keys(data))
      this.isZaixianArr = Object.keys(data)
      this.getMyfriendsFun()
    }
  },
image.png
 async getMyfriendsFun() {
      try {
        const res = await getMyfriends()
        let arr = res.data
        console.log(this.isZaixianArr);
        const idSet = new Set(this.isZaixianArr)
        // https://blog.csdn.net/yiyueqinghui/article/details/107773347
        console.log(idSet);
        const res1 = arr.map(o => ({ ...o, isZaixian: idSet.has(o._id) ? 1 : o.isZaixian }))
        this.list = res1.sort(function (a, b) {
            return b.isZaixian - a.isZaixian
          })
      } catch (error) {
        console.log(error)
      }
    },
上一篇下一篇

猜你喜欢

热点阅读