一、問題描述
?? 對(duì)于 ios 系統(tǒng)析恢,輸入框輸入內(nèi)容,軟鍵盤彈出映挂,頁面內(nèi)容整體上移,但是軟鍵盤收起柑船,頁面內(nèi)容不會(huì)自動(dòng)回到原本的位置泼各,必須手動(dòng)下拉才會(huì)恢復(fù)
?? 剛開始遇到的時(shí)候,心想真是什么鬼畜問題都有扣蜻,這邊直接給出解決辦法了
二、解決方式
首先在你們函數(shù)工具文件中加上下面的函數(shù)
// util.js
function inputBlur () {
let u = navigator.userAgent
let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
if (isIOS) {
setTimeout(() => {
const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
window.scrollTo(0, Math.max(scrollHeight - 1, 0))
}, 200)
}
}
在具體的文件中使用方式如下:
<!-- 加上 @blur.prevent="checkValue" -->
<input
v-model="inputValue"
placeholder="請(qǐng)輸入"
type="text"
@blur.prevent="checkValue"
>
checkValue() 函數(shù)
checkValue () {
inputBlur()
this.$emit('checkValue')
},
至此, 關(guān)于 ios 軟鍵盤整出的雞肋問題就解決啦