vue实现滚动回到顶部和input框自动获取焦点

编程入门 行业动态 更新时间:2024-10-26 18:16:12

vue实现滚动回到顶部和input框自动获取<a href=https://www.elefans.com/category/jswz/34/1766386.html style=焦点"/>

vue实现滚动回到顶部和input框自动获取焦点

vue实现滚动回到顶部和input框自动获取焦点

<template><div class="preview" ref="scrollRef"><inputtype="text"placeholder="请填写投放名称"v-model="launchInfo.demandLaunchPlanName"class="launch-name"ref="input"/></div><div @click="top">回到顶部并获取焦点</div>
</template>
methods: {top(){//获取需要回到顶部的节点的位置let top = this.$refs.scrollRef.scrollTop// 缓慢滚动回到顶部const timeTop = setInterval(() => {this.$refs.scrollRef.scrollTop = top -= 50if (top <= 0) {clearInterval(timeTop)}}, 30)// input框获取焦点this.$nextTick(() => {this.$refs.input.focus();})}
}

更多推荐

vue实现滚动回到顶部和input框自动获取焦点

本文发布于:2024-03-05 03:40:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1711217.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:焦点   vue   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!