vue 滚动条自动到底部
不用jquery,scrolltop不会不能赋值,使用 ref ,一句代码解决需求注意:这里使用this.$nextTick是为了方便更多的人使用,在修改数据之后使用 $nextTick,可以在回调中获取更新后的 DOM如果只是在一进入页面就滚到底部,在当前页面没有操作进行DOM更新,就可以省略this.$nextTick<template><div clas...
·
不用jquery,scrolltop不会不能赋值,使用 ref ,一句代码解决需求
注意:这里使用this.$nextTick是为了方便更多的人使用,在修改数据之后使用 $nextTick,可以在回调中获取更新后的 DOM
如果只是在一进入页面就滚到底部,在当前页面没有操作进行DOM更新,就可以省略this.$nextTick
<template>
<div class="main" ref="main">
<div ref="content">Lorem ipsum dolor sit amet consectetur adipisicing elit. Veritatis, nesciunt ea consequatur quisquam nostrum alias atque aliquam inventore expedita explicabo aspernatur doloremque distinctio necessitatibus culpa ducimus eaque accusamus. Quis, similique!
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ab quasi maxime voluptate accusamus rem consectetur laborum porro mollitia dicta nisi quas facere commodi quaerat sunt ea, iste explicabo, maiores atque.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti recusandae delectus iure fugiat, vitae veniam ipsam quas ullam explicabo, corrupti optio quidem hic quam nisi inventore aperiam laborum atque! Ducimus!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Neque non excepturi amet ex, tempora corporis repellat accusamus culpa aperiam perferendis reprehenderit illum consequuntur. Nemo nisi assumenda similique harum officia minus!
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Maxime eos eligendi, dolorum ullam reprehenderit ipsam et voluptas voluptatem facilis nobis animi at laudantium facere incidunt. Rerum sed nisi enim hic.
</div>
</div>
</template>
<script>
export default {
name: 'home',
mounted(){
this.$nextTick(() => {
this.$refs.main.scrollTop = this.$refs.content.scrollHeight;
})
}
}
</script>
<style>
.main{
width: 100%;
height: 200px;
padding: 10px;
box-sizing: border-box;
background-color: pink;
overflow: auto;
}
</style>
</script>
更多推荐
已为社区贡献2条内容
所有评论(0)