vue窗口內(nèi)容滾動到底部實現(xiàn)過程
更新時間:2025年12月17日 09:00:53 作者:巨蟹座守護騎士
這篇文章主要介紹了vue窗口內(nèi)容滾動到底部實現(xiàn)過程,以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家,
vue窗口內(nèi)容滾動到底部
onMounted(() => {
scrollToBottom()
})
// 滾動到底部方法
const scrollToBottom = () => {
// 獲取聊天窗口容器
let chatRoom: any = document.querySelector(".chat-content");
// 滾動到容器底部
chatRoom.scrollTop = chatRoom.scrollHeight;
}效果

聊天窗口代碼
<template>
<div class="chat">
<div class="left">
<div class="top">
<ClientOnly>
<el-input v-model="search" style="width: 240px;" placeholder="搜索聯(lián)系人" :suffix-icon="Search" />
</ClientOnly>
</div>
<div class="ul">
<div class="li" v-for="item, i in 5" :key="i">
<div class="img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="content">
<div class="name">前端</div>
<div class="text text_ov1">大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝</div>
</div>
<div class="tiem">
18:00
</div>
</div>
</div>
</div>
<div class="right">
<div class="chat-name">前端</div>
<!-- 聊天內(nèi)容 -->
<div class="chat-content">
<!-- 收到的 -->
<div class="chat-item">
<div class="chat-img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="chat-text">
大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝!大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝
</div>
</div>
<!-- 發(fā)送的 -->
<div class="my_chat-item" v-for="item, i in 10" :key="i">
<div class="chat-img">
<img src="/assets/images/head/user.jpg" alt="">
</div>
<div class="chat-text">
大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝!大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝大佬,請問這個怎么寫?看到請回復(fù)一下,謝謝
</div>
</div>
</div>
<!-- 輸入框 -->
<div class="chat-input">
<div class="rest">
<div class="ul">
<div class="li">
<i class="iconfont icon-smile"></i>
</div>
<div class="li">
<i class="iconfont icon-tupian"></i>
</div>
</div>
<div class="publish">發(fā)送</div>
</div>
<ClientOnly>
<el-input type="textarea" resize="none" :autosize="{ minRows: 6, maxRows: 6 }" maxlength="500" show-word-limit
placeholder="" v-model="message">
</el-input>
</ClientOnly>
</div>
</div>
</div>
</template><script setup lang="ts">
import { Search } from '@element-plus/icons'
let search = ref("");
let message = ref("");
onMounted(() => {
scrollToBottom()
})
// 滾動到底部方法
const scrollToBottom = () => {
// 獲取聊天窗口容器
let chatRoom: any = document.querySelector(".chat-content");
// 滾動到容器底部
chatRoom.scrollTop = chatRoom.scrollHeight;
}
</script>
<style scoped lang="scss">
.chat {
margin-left: 22px;
width: 1030px;
border-radius: 12px;
background: #ffffff;
display: flex;
.left {
padding-top: 10px;
border-right: 1px solid #dddddd;
width: 255px;
.top {
display: flex;
justify-content: center;
align-items: center;
height: 55px;
}
.ul {
.li {
padding: 15px;
background-color: #fff;
height: 66px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #E4E7ED;
cursor: pointer;
&:hover {
background: #F1F6FF;
}
.img {
width: 42px;
height: 42px;
overflow: hidden;
border-radius: 50%;
margin-right: 10px;
img {
width: 100%;
}
}
div.content {
width: 60%;
div.name {
font-size: 14px;
color: #303133;
}
div.text {
margin-top: 2px;
font-size: 12px;
color: #3D3D3D;
}
}
div.tiem {
font-size: 12px;
color: #3D3D3D;
}
}
}
}
.right {
padding-top: 10px;
flex: 1;
.chat-name {
border-bottom: 1px solid #dddddd;
height: 55px;
line-height: 55px;
padding-left: 20px;
}
/**聊天框*/
div.chat-content {
overflow-y: scroll;
height: 500px;
padding: 20px 10px;
&::-webkit-scrollbar {
/**display: none;*/
width: 5px !important;
}
/**我接收的*/
div.chat-item {
display: flex;
margin-top: 20px;
div.chat-img {
width: 48px;
height: 48px;
border-radius: 50%;
overflow: hidden;
margin-right: 5px;
img {
width: 100%;
}
}
div.chat-text {
background: #EEEEEE;
border-radius: 6px;
padding: 10px;
margin-right: 200px;
font-size: 14px;
color: #3D3D3D;
line-height: 20px;
flex: 1;
}
}
/**我發(fā)送的*/
div.my_chat-item {
display: flex;
flex-direction: row-reverse;
margin-top: 20px;
div.chat-img {
width: 48px;
height: 48px;
border-radius: 50%;
overflow: hidden;
margin-left: 5px;
img {
width: 100%;
}
}
div.chat-text {
background: #EEEEEE;
border-radius: 6px;
padding: 10px;
flex: 1;
margin-left: 200px;
font-size: 14px;
color: #3D3D3D;
line-height: 20px;
}
}
}
.chat-input {
height: 30%;
border-top: 1px solid #dddddd;
.rest {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px 20px;
.ul {
display: flex;
.li {
margin-right: 20px;
i {
color: #3D3D3D;
cursor: pointer;
}
}
}
}
// 清除文本域邊框
:deep(.el-textarea__inner) {
box-shadow: 0 0 0 0px;
}
:deep(.el-textarea__inner:hover) {
box-shadow: 0 0 0 0px;
}
:deep(.el-textarea__inner:focus) {
box-shadow: 0 0 0 0px;
}
.publish {
cursor: pointer;
width: 74px;
height: 28px;
border-radius: 14px;
text-align: center;
line-height: 28px;
background: #fff;
color: #888888;
font-size: 14px;
border: 1px solid #888888;
&:hover {
background: #C4302C;
color: #fff;
border: 1px solid #ffffff00;
}
}
}
}
}
</style>總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue最強table vxe-table 虛擬滾動列表 前端導(dǎo)出問題分析
最近遇到個問題,后臺一次性返回2萬條列表數(shù)據(jù)并且需求要求所有數(shù)據(jù)必須全部展示,不能做假分頁,怎么操作呢,下面通過本文介紹下vue最強table vxe-table 虛擬滾動列表 前端導(dǎo)出問題,感興趣的朋友一起看看吧2023-10-10
vue使用JSEncrypt對密碼本地存儲時加解密的實現(xiàn)
本文主要介紹了vue使用JSEncrypt對密碼本地存儲時加解密,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
組件中多個el-upload存在導(dǎo)致上傳圖片失效的問題及解決
這篇文章主要介紹了組件中多個el-upload存在導(dǎo)致上傳圖片失效的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03
vue中解決chrome瀏覽器自動播放音頻和MP3語音打包到線上的實現(xiàn)方法
這篇文章主要介紹了vue中解決chrome瀏覽器自動播放音頻和MP3語音打包到線上的實現(xiàn)方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10
vue使用高德地圖實現(xiàn)實時定位天氣預(yù)報功能
這篇文章主要介紹了vue使用高德地圖實現(xiàn)實時天氣預(yù)報功能,根據(jù)定位功能,使用高德地圖實現(xiàn)定位當(dāng)前城市的天氣預(yù)報功能,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2022-05-05
vue如何基于el-table實現(xiàn)多頁多選及翻頁回顯過程
在最近的一個項目中我需要實現(xiàn)表格的翻頁,并且還要實現(xiàn)全選、多選功能,下面這篇文章主要給大家介紹了關(guān)于vue如何基于el-table實現(xiàn)多頁多選及翻頁回顯過程的相關(guān)資料,需要的朋友可以參考下2022-12-12
vue 中常用操作數(shù)組的方法(forEach()和reduce())
文章介紹了JavaScript中常用的操作數(shù)組方法,包括forEach()和reduce(),forEach()用于遍歷數(shù)組并對每個元素執(zhí)行操作,而reduce()則用于遍歷數(shù)組并進行累加等迭代操作,感興趣的朋友一起看看吧2025-03-03
VUE側(cè)邊導(dǎo)航欄實現(xiàn)篩選過濾的示例代碼
本文主要介紹了VUE側(cè)邊導(dǎo)航欄實現(xiàn)篩選過濾的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

