今天使用el-select的@blur方法,发现第一次选择失去焦点后,没获取到选择的值(e.target.value)
解决方法:
1 采用计时器
<el-select v-model="scope.row.targetId"
:disabled="disabled"
clearable
placeholder="请选择"
filterable
automatic-dropdown
@blur="blurSelect">
<el-option v-for="(item,index) in fileType"
:key="index"
:label="item.name"
:value="item.targetId" />
</el-select>
// el-select失去焦点必填校验
blurSelect(e) {
setTimeout(()=> {
if(!e.target.value) {
this.$message.warning('请选择必填项!')
}
},1000)
},
2 采用focus来获取blur
<el-select
v-model="scope.row.targetId"
ref="fuzzySearch"
multiple
placeholder="请选择"
filterable
automatic-dropdown
@focus="focusSelectValue"
>
<el-option v-for="(item,index) in fileType"
:key="index"
:label="item.name"
:value="item.targetId" />
</el-select>
focusSelectValue() {
console.log(this.$refs.fuzzySearch);
this.$refs.fuzzySearch.$refs.input.blur = () => {
console.log(this.$refs.fuzzySearch.$refs.input.value);
};
},