One effective approach is to scroll to the current scrollHeight
of the reference element once the list has been updated.
Example
new Vue({
el: '#app',
name: "HelloWorld",
props: {
msg: String,
},
data() {
return {
list: [],
};
},
mounted() {
let i = 0;
for (i = 0; i < 19; i++) {
this.list.push(i);
}
},
methods: {
addItem() {
this.list.push(0);
setTimeout(() => {
const targetTop = this.$refs.hello.scrollHeight;
this.$refs.hello.scrollTo({
top: targetTop,
left: 0,
behavior: "smooth",
});
})
},
}
})
.hello {
overflow-y: auto;
height: 200px;
border: 1px solid black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.4/vue.js"></script>
<div id="app">
<div class="hello" ref="hello">
<h1>{{ msg }}</h1>
<div v-for="item in list" :key="item">
<div style="margin-bottom: 20px">{{ item }}</div>
</div>
<button @click="addItem">add</button>
</div>
</div>