element el-time-select 搭配 MessageBox使用,给 el-time-select 添加 @focus事件弹出this.$alert,弹出的提示框关闭后马上又弹出

问题: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-selectinput失去焦点
timeChange() {
      if (this.dateValue == '') {
        this.$alert('请先选择日期', '提示')
        this.$refs.selectRef.blur()
      }
    }
注意: this.$refs.selectRef.blur()这样写是无效的
timeChange() {
      this.$alert('这是一段内容', '标题名称', {
          confirmButtonText: '确定',
          callback: action => {
            this.$refs.selectRef.blur()
          }
        });
      }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值