// 第一次獲取數(shù)據(jù)放在聊天頁面中
if (!this.message.length) {
this.message = res.data.list // 聊天列表
this.$nextTick(() => {
const div = document.getElementById('messgaeContent')
div.scrollTop = div.scrollHeight // 滾動到最下面
this.scrollHeight = div.scrollTop // 記錄上一次滾動的距離
})
} else {
this.message.unshift(...(res.data.list)) // 在數(shù)組最前面放數(shù)據(jù)
this.$nextTick(() => {
const div = document.getElementById('messgaeContent')
div.scrollTop = div.scrollHeight - this.scrollHeight - this.$refs.scrollRef.offsetHeight // 內容全文高 - 上一次滾動距離 - 本身內容高
})
}
內容全文高 - 上一次滾動距離 - 本身內容高就是當前位置文章來源地址http://www.zghlxwxcb.cn/news/detail-406395.html
文章來源:http://www.zghlxwxcb.cn/news/detail-406395.html
到了這里,關于聊天——拉去歷史記錄,保持聊天頁面靜止的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!