<template>
<div class="scrollable" ref="scrollable">
<!-- 这里是滚动内容 -->
</div>
</template>
<script>
export default {
mounted() {
// 在组件挂载后,获取滚动容器的 DOM 元素
this.scrollable = this.$refs.scrollable;
},
methods: {
// 在这里添加新内容
addContent(content) {
// 将新内容添加到 DOM 中
this.$refs.content.appendChild(content);
// 滚动条滚动到底部
this.scrollable.scrollTop = this.scrollable.scrollHeight;
},
}
};
</script>