JS之el-input 回车触发事件并且重新聚焦全选文本

el-input 回车触发事件并且重新聚焦全选文本

<el-input
    style="width:140px;"
    v-model="value"
    @keyup.enter.native="enterInput"
    @focus="getInputFocus($event)"
    ref="toFoucus"
/>

———————————————————————

methods: {
    enterInput() {
      this.$refs.toFoucus.select()  // 重新选择
      this.$nextTick(() => {
        this.$refs.toFoucus.focus();//输入框默认获取焦点
      });
    },
     getInputFocus(event) {
      event.currentTarget.select();
    }
}
posted @ 2021-12-10 10:34  bugSource  阅读(637)  评论(0编辑  收藏  举报