element-plus [Component] [input] input

2g32fytz  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(50)

Bug Type: Component

Environment

  • Vue Version: 3.2.45
  • Element Plus Version: 2.3.3
  • Browser / OS: 谷歌
  • Build Tool: Vite

Reproduction

  • el-input

Element Plus Playground

Steps to reproduce

<el-input v-model="test" clearable @Focus="focus" @clear="clear">
const test=ref('')
const focus=()=>{
console.log(1);
}
const clear=()=>{
console.log(2);
}

What is Expected?

clear的时候不会触发focus

What is actually happening?

clear的时候会触发focus

Additional comments

(empty)

bjp0bcyl

bjp0bcyl1#

For the control, it is already in the focused state, why should it trigger the focus again?

baubqpgj

baubqpgj2#

虽然不理解你这个需求的目的,但还是做了个demo
点击clear实际触发了的操作是:focus方法(初始状态未聚焦)->clear方法(此时已聚焦)
所以我的思路是clear方法触发时手动失焦,并增加一个状态
clear方法失焦后,会被element再次聚焦,这时会再次触发focus方法
通过状态判断是,进行二次失焦
这时触发操作就变成了:focus方法(初始状态未聚焦)->clear方法(手动失焦并设定状态)->focus方法(根据状态手动失焦并还原状态避免影响后续focus)
Element Plus Playground

相关问题