你可以使用ref来获取el-input元素的引用,然后在请求后端接口报错时调用blur方法移除鼠标焦点。以下是一个示例代码:

<template>
  <div>
    <el-input ref="input" v-model="inputValue" @keyup.enter="requestAPI"></el-input>
  </div>
</template>

<script>
export default {
  data() {
    return {
      inputValue: ''
    }
  },
  methods: {
    requestAPI() {
      // 发送请求
      // 如果请求报错,移除鼠标焦点
      if (error) {
        this.$refs.input.blur();
      }
    }
  }
}
</script>

在上面的代码中,我们使用refel-input元素添加了一个引用input,然后在requestAPI方法中,如果请求报错,我们就可以通过this.$refs.input来获取el-input元素的实例,并调用其blur方法移除鼠标焦点

vue中el-input框输入之后回车请求后端接口我想要在请求后端接口报错是移除掉这个这个el-input框的鼠标焦点

原文地址: http://www.cveoy.top/t/topic/iZn1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录