焦点"/>
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框自动获取焦点
发布评论