Vue 中 el-input 输入框回车请求接口报错后移除焦点
<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>
<p>在上面的代码中,我们使用<code>ref</code>给<code>el-input</code>元素添加了一个引用<code>input</code>,然后在<code>requestAPI</code>方法中,如果请求报错,我们就可以通过<code>this.$refs.input</code>来获取<code>el-input</code>元素的实例,并调用其<code>blur</code>方法移除鼠标焦点。</p>
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qFos 著作权归作者所有。请勿转载和采集!