項目中遇到的需求:
輸入框默認獲取焦點,回車後選中文本信息
<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();//輸入框默認獲取焦點
});
},
}