overflow:auto自动滚动到底部(vue)

在做消息的项目,当有新消息的时候让新消息出现在最底部,此时的box用的是overflow:auto
注:vue项目需要注意在dom结构渲染完再进行操作

<ul class="box"  ref="chatContent">
					<li v-for='item,index in direction' :class='item'>
						<span class="name">{
   
   {name[index]}}</span>
						<span class="message">{
   
   {message[index]}}</span>
					</li>
				</ul>



this.$nextTick(() =>{
					this.$refs.chatContent.scrollTop = this.$refs.chatContent.scrollHeight;
				})

jquery代码实现

$('.chatRoom .room .box').scrollTop($(".box")[0].scrollHeight)

猜你喜欢

转载自blog.csdn.net/qq_40557812/article/details/85051011