PeaceSheep's blog PeaceSheep's blog
首页
  • 分类
  • 标签
  • 归档
相关链接
提建议&咨询&赞赏
GitHub (opens new window)

PeaceSheep

以最简洁、易懂的话解决问题
首页
  • 分类
  • 标签
  • 归档
相关链接
提建议&咨询&赞赏
GitHub (opens new window)
  • web

    • element-plus滚动条滚动到底部
    • mac使用docker部署nextcloud-aio并为本地域名添加https支持(未成功)
    • 前端处理POST类型的sse请求
    • 网站域名迁移的百度和谷歌SEO优化
    • 使用腾讯云OSS作为个人网站文件处理的存储库
    • 使用cloudflare-r2搭建webdav
  • 物联网与路由器

  • 操作系统

  • 错误解决

  • 使用技巧

  • 教程
  • web
PeaceSheep
2023-04-23

element-plus滚动条滚动到底部

<el-scrollbar ref="scrollContainerRef" height="50vh" class="message-box">
    <div ref="scrollContentRef">
        <div v-for="message in messages" :key="message.id" class="message">
        </div>
    </div>
</el-scrollbar>

<script lang="ts" setup>
const scrollContainerRef: any = ref(null);
const scrollContentRef:any = ref(null);

const addMsg = (messageObj: any, sendBySelf: boolean) => {
    if (scrollContainerRef.value != null && scrollContentRef.value!=null) {
        nextTick(() => {
            scrollContainerRef.value!.setScrollTop(scrollContentRef.value!.clientHeight)
        })
       

    } 
}
</script>



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

需要注意的点有:

  1. 需要对scollbar设置高度,如果没有设置,但是下面的div设置了高度,会导致滚动条还是原生滚动条,因为这个找了很久。
  2. 必须要放在nextTick函数里面,不然由于Vue的异步更新机制,可能导致执行代码的时候DOM还没有更新,即scrollContentRef.value!.clientHeight还是原来的值。
编辑 (opens new window)
上次更新: 2025/04/15, 10:52:45
mac使用docker部署nextcloud-aio并为本地域名添加https支持(未成功)

mac使用docker部署nextcloud-aio并为本地域名添加https支持(未成功)→

最近更新
01
ubuntu安装g++显示已有但是输入g++又找不到命令
04-15
02
使用cloudflare-r2搭建webdav
04-08
03
LLM聚合平台客户端对比
03-29
更多文章>
Theme by Vdoing | Copyright © 2022-2025 PeaceSheep
冀ICP备2022004632号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式