以Vue为例子,其他依次类推
//监听数据更新
watch: {
data: function (data) {
//this.$nextTick是vue内置的一个方法,具体百度
this.$nextTick(() => {
var container = this.$el.querySelector("#chat-list");//#chat-list为ul的id
container.scrollTop = container.scrollHeight;
//如果上述代码不行,依次尝试以下3个代码
1.document.documentElement.scrollTop = container.scrollHeight;
2.window.pageYOffset = container.scrollHeight;
3.document.body.scrollTop = container.scrollHeight;
});
},
},