element 阻止$confirm回车确认
最近在开发基于elementUI和Vue项目,得到了一个重置密码的需求:点击重置出现弹窗提示键盘回车键默认要取消我在这里插入代码片
·
最近在开发基于elementUI和Vue项目,得到了一个重置密码的需求:
- 点击重置出现弹窗提示
- 键盘回车键默认要取消
方法一:通过添加beforeClose方法,阻止回车默认确定的功能。
methods: {
resetPwd(){
this.$confirm('确定重置密码', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
beforeClose(action, instance, done){
if(action == 'confirm'){
instance.$refs['confirm'].$el.onclick = a()
function a(e){
e = e || window.event;
if(e.detail != 0){
done()
}
}
}else{
done()
}
}
}).then((res) => {
}).catch(() => {
})
}
},
方法二:在created中对键盘事件进行监听,当为回车事件时关闭confirm弹窗。
created() {
document.onkeydown = (e) => {
var key = window.event.keyCode
if (key === 13) {
this.$msgbox.close()
}
}
}
以上就是我对confirm的理解,如果文章由于我学识浅薄,导致您发现有严重谬误的地方,请一定在评论中指出,我会在第一时间修正我的文章,以避免误人子弟。
更多推荐
已为社区贡献4条内容
所有评论(0)