[不懂就来问] confirm 没有阻塞运行为什么,先打印了 发送,后面才弹出对话框。请指导下 谢啦

2020-05-27 15:29:06 +08:00
 whatCanIDoForYou
let _need_return = false;
if( _match != `` ){
// this.openconfirm(`第${i + 1}条最终用户料号存在特殊字符:`+_match);
this.$confirm(`第${i + 1}条最终用户料号存在特殊字符:`+_match, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(() => {
console.log("我点了确认")
_need_return = false;
})
.catch(() => {
console.log("我点击了取消")
_need_return = true;
this.$message({
type: "info",
message: "已取消删除"
});
});
}
console.log("发送")
return;
1991 次点击
所在节点    JavaScript
5 条回复
whatCanIDoForYou
2020-05-27 15:41:44 +08:00
查了下。好像目前支持阻塞的只有 alert...... 但是有一个疑问,我想的是无论是否点击确定,或者取消,只要在弹出对话框时都去阻断函数,这个问题怎么解决
ghosthcp516
2020-05-27 15:45:44 +08:00
你这个是 element-ui 的确认框吧, 它封装了个 Promise,按 Promise 的逻辑去处理, 不是原生的 confirm 。
ciaoly
2020-05-27 15:48:01 +08:00
把外层函数变成 async 的,用 await
whatCanIDoForYou
2020-05-27 15:53:11 +08:00
@ghosthcp516 #2 问题解决了。 他这个是封装的 ,可惜刚接触 vue 他封装到那里,我没有找到,我用了原生的
const answer = window.confirm(`第${i + 1}条最终用户料号存在特殊字符:`+_match)
if (answer) {
console.log("我点了确认")
} else {
console.log("我点击了取消")
return;
}
已经 OK 了。
当然还希望指导下 怎么找到他封装的这个公共方法的包。。。
ghosthcp516
2020-05-28 10:31:20 +08:00
@whatCanIDoForYou node_modules/element-ui/packages/message-box

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/675995

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX