困扰了一天
直接晒代码吧!!!
//监听输入框获得焦点
const handleFocus = (e) => {
nextTick(() => {
const footerElement = footerEle.value;
console.log(footerElement.offsetTop);
if (footerElement) {
setTimeout(() => {
// 延迟执行以等待软键盘完全弹出
scrollContainer.value.scrollTo({
top: footerElement.offsetTop,
behavior: "smooth",
});
}, 100);
}
});
};
其中给field注册focus事件,footerElement是获取的输入框节点(输入模块!不是就一个field),scrollContainer是获取的聊天界面节点