项目中遇到的需求:
输入框默认获取焦点,回车后选中文本信息
<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();//输入框默认获取焦点
});
},
}