小程序长列表渲染

// 消息组件,通过监听消息显示隐藏超出屏幕的消息内容,超出屏幕部分用空标签代替,height撑起高度
// 数据格式变成二维数组 可以减少监听的数量 提高性能

<div :id="'n' + item._id" :style="{'height': showChat ? '' : (height + 'px')}">
  <div :class="{cur: !showChat}">
	// 消息内容
  </div>
</div>

computed: {
    if (that.observerInstance) {
		return
    }
	that.disconnectObserve()
	that.observerInstance = wx.createIntersectionObserver()
	that.$nextTick(function () {
		let timerA = setTimeout(function () {
			that.observerNode()
			clearTimeout(timerA)
		}, 50)
	})
}


disconnectObserve() {
	let that = this
	if (that.observerInstance) {
		that.observerInstance.disconnect()
		that.observerInstance = null
	}
},


observerNode() {
	let that = this
	let id = 'n' + that.item._id
	let dis = -40
	try {
		that.observerInstance.relativeToViewport({top: dis, bottom: dis}).observe('#' + id, res => {
            that.height = res.boundingClientRect.height
			if (res.intersectionRatio === 0) {
				that.showChat = false
			} else {
				that.showChat = true
			}
		});
	} catch (error) {
	}
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值