场景:部分安卓机(例如one plus 7 pro)
解决方案:
<script>
export default {
data(){
return {
visibleChangeObject: null
}
},
mounted(){
this.visibleChangeObject = this.visibleChange();
this.visibleChangeObject.add();
},
beforeDestroy() {
this.visibleChangeObject && this.visibleChangeObject.remove();
},
methods: {
visibleChange() {
const handleVisibilityChange = () => {
// if (document.visibilityState == 'hidden') { //隐藏界面
// }
if (document.visibilityState == 'visible') { //重新打开界面
if( isAndroid ) {
const currentInput = document.createElement("input");
document.body.appendChild(currentInput);
currentInput.select();
document.body.removeChild(currentInput);
}
}
};
return {
add: () => document.addEventListener('visibilitychange', handleVisibilityChange, false),
remove: () => document.removeEventListener('visibilitychange', handleVisibilityChange, false),
};
}
}
}
</script>