uniapp将聊天页面定位始终定位到最底部展示 Published on May 29, 2024 in 随笔 with 0 comment 在制作IM即时通讯的时候,常常因为发出的消息不能定位到最底部,对于新手来说比较烦恼,复制下面这段代码就能实现聊天始终定位在最底部 ``` this.$nextTick(() => { // document.getElementById("scrolldIV2").scrollIntoView(); //h5端定位到指定位置 setTimeout(() => { uni.createSelectorQuery().select(".cu-chat").boundingClientRect(function(res) { //定位到你要的class的位置 console.log("标签获取====>", res) uni.pageScrollTo({ scrollTop: res.height, duration: 0 }); }).exec() }, 50) //this.viewIndex = "im_" + this.ChatList.length; }) ``` 本文由 admin 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。