问题:element el-time-select 搭配 MessageBox使用,给 el-time-select 添加 @focus事件弹出提示框,弹出的提示框关闭后马上又弹出
原因:el-time-select添加聚焦事件弹出提示框,关闭提示框,但el-time-select下input输入框一值处于聚焦状态,因此提示框在关闭后会继续弹出,陷入死循环,因此在关闭提示框后需要让el-time-select的input失去焦点
解决办法:
<el-time-select
ref="selectRef"
v-model="timeValue"
@focus="timeChange"
:picker-options="{
start: start,
step: '00:30',
end: '19:30'
}"
placeholder="选择时间">
</el-time-select>
给el-time-select添加ref="selectRef"
,然后在timeChange()
事件里让el-time-select
的input
失去焦点
timeChange() {
if (this.dateValue == '') {
this.$alert('请先选择日期', '提示')
this.$refs.selectRef.blur()
}
}
注意: this.$refs.selectRef.blur()
这样写是无效的
timeChange() {
this.$alert('这是一段内容', '标题名称', {
confirmButtonText: '确定',
callback: action => {
this.$refs.selectRef.blur()
}
});
}