vue项目中input框默认获得焦点,回车选中输入文本

项目中遇到的需求:

输入框默认获取焦点,回车后选中文本信息

<input ref="code" type="text"  @keyup.enter="enterPress()" v-model="code"/>
export default {
    data() {
	return {
            code:'',
        }
    },
    methods:{
        enterPress() {//回车事件
            this.$refs.code.select();//输入框选中状态
        }
    },
    mounted() {
	this.$nextTick(() => {
	  this.$refs.code.focus();//输入框默认获取焦点
	});
    },
    
}
发布了94 篇原创文章 · 获赞 42 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_29483485/article/details/100556869