因此,我必须尝试在返回之前创建一个等待用户输入的异步函数,但是,我不太确定如何做到这一点:
async createAlert() {
return await swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
reverseButtons: true
}).then(function (result) {
//user has answered we want to return the result
})
}这个jquery创建了以下弹出窗口:

当用户按下任意一个按钮时,代码的(then)部分就会执行,这里我想返回结果
谁能给我指明正确的方向?
发布于 2018-06-21 08:34:52
试着这样做:
async createAlert() {
try{
let result = await swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
reverseButtons: true
});
// SUCCESS
return result;
}catch(e){
// Fail!
console.error(e);
}
}https://stackoverflow.com/questions/50963914
复制相似问题