【vue】div元素内的滚动条 滚动到指定位置
2022-01-03 本文已影响0人
吃肉肉不吃肉肉
<template>
<div class="GoodList">
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
<div>123</div>
</div>
</template>
<script>
export default{
mounted(){
this.scrollToBottom()
},
methods:{
scrollToBottom(){
this.$nextTick(()=>{
let box = this.$el.querySelector(".GoodList")
GoodList.scrollTop = 40 //滚动到距离元素顶部 40px
})
}
},
}
</script>
<style>
.GoodList{
height: 200px;
overflow-y: scroll;
}
</style>