为什么会产生这样的bug:因为表单没有获得焦点!
1.首先这个组件是vue-cron嵌套的element ui input,但还是el-input影响不大
2.这是我遇到的问题,但它第二次点击保存时就好了,我为了解决这个一次性就能让输入框判断的方法,我想到的是输入框失去焦点。
3.解决这个办法:
<!-- 自定义vue-cron组件 -->
<div slot="taskCronForm" slot-scope="{ row }" >
<el-popover v-model="cronPopover" >
<cron @change="changeCron" @close="cronPopover=false"></cron>
<el-input slot="reference" @click="cronPopover=true" v-model="row.taskCron"
@blur="blurInput(row)" ref="input"></el-input>
</el-popover>
</div>
data(){
return {
timer:null
}
}
methods:{
changeCron(val) { // vue-cron组件保存方法
this.rows.taskCron = val;
this.$refs.input.focus();
this.$nextTick(() => { // 为什么要用定时器,为了解决任务表达式的框验证问题
this.timer = setTimeout(() => {
this.$refs.input.blur();
},100)
})
},
}
beforeDestroy() {
clearInterval(this.timer);
this.timer = null;
}