<script setup lang="ts">
import { dayjs } from 'element-plus';
import { ElScrollbar as ElScrollbarType } from 'element-plus';
const innerRef = ref<HTMLDivElement>()
const scrollbarRef = ref<InstanceType<typeof ElScrollbarType>>()
const items = ref<string[]>([])
const handleClick = () => {
items.value.push(dayjs().format('YYYY-MM-DD HH:mm:ss SSS'));
nextTick(() => {
if (innerRef.value!.clientHeight > 200) {
scrollbarRef.value!.setScrollTop(innerRef.value!.clientHeight)
}
})
}
</script>
<template>
<el-scrollbar height="200px" ref="scrollbarRef" always>
<div ref="innerRef">
<p v-for="item in items" :key="item" class="scrollbar-demo-item">{{ item }}</p>
</div>
</el-scrollbar>
<el-button type="primary" @click="handleClick">add</el-button>
</template>
<style scoped>
.scrollbar-demo-item {
display: flex;
align-items: center;
justify-content: center;
height: 50px;
margin: 10px;
text-align: center;
border-radius: 4px;
background: #ecf5ff;
color: #409eff;
}
</style>
DEMO代码地址: GitHub - rdzhaoxin/scrollbar-demo: vue3 element plus scrollbar demo文章来源:https://www.toymoban.com/news/detail-527503.html
在线预览:Glitch :・゚✧文章来源地址https://www.toymoban.com/news/detail-527503.html
到了这里,关于Element Plus滚动条el-scrollbar始终保持在底部的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!