零时解决方案
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#app {
height: 100vh;
position: relative;
}
input {
position: absolute;
bottom: 0;
left: 0;
}
</style>
<script src='https://unpkg.com/vue@next'></script>
<script src='https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js'></script>
</head>
<body>
<div id="app">
<input type="text" @focus="scrollViewPosition" />
</div>
</body>
<script>
const App = {
data() {
return {}
},
methods: {
scrollViewPosition() {
try {
if (document.activeElement.tagName === "INPUT") {
setTimeout(() => {
document.activeElement.scrollIntoViewIfNeeded(true);
}, 100);
}
} catch (error) {
console.log(error);
}
}
}
}
const app = Vue.createApp(App)
app.mount('#app')
</script>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)