Framework : uniapp vue2
Problem : When the textarea input box is clicked, the soft keyboard opens and the page is pushed up. When the focus is lost, the soft keyboard closes, but the page remains pushed up and cannot be pulled down manually
Solution :
Brief description : Call the method triggered when the input box loses focus. There is an official method . When the focus is lost, assign the height of the page to the height when she opened the soft keyboard. The official also has a method to control the scrolling position of the page .
Note
There are many ways to get the height of the page. Ordinary pages (non-nvue, v-if, parent-child components) can use the official life cycle (onPageScroll) to monitor the height. However, since my page is rendered using the v-if conditional judgment, I use thescroll method in the scroll-view component to monitor.
<scroll-view v-else-if="showPage === 'happen'" scroll-y @scroll="scroll">
......
<textarea @blur="textBlur"/>
......
</scroll-view>
scroll(event) {
this.scrollTopPX = event.detail.scrollTop
},
textBlur() {
uni.pageScrollTo({
scrollTop: this.scrollTopPX,
duration: 300,
})
},