SweetAlert确认后关闭的问题

https://img3.mukewang.com/5b7a302300015af607320563.jpg

最近用上了swal,项目需要,colseOnConfirm:true,因为“点击之后提示框不能loading住页面,不能防止用户再次点击”,所以设为true点击之后关闭,设为true问题又来了,如果执行太快里面的swal就不会弹出提示了,需要setTimeOut等待几秒钟才能弹出提示,真是蛋疼,你们有什么好的方法啊


尚方宝剑之说
浏览 1912回答 1
1回答

FFIVE

因为动画有延迟, 可以用promise,进行二次封装。window.mconfirm = function (options) {var prom = new Promise(function (resolve, reject) {var swalOptions = {title: "",text: "",showCancelButton: true,confirmButtonColor: "#DD6B55",confirmButtonText: "确认",cancelButtonText: "取消",closeOnConfirm: true,closeOnCancel: true};if (typeof(options) == 'object') {swalOptions = $.extend(swalOptions, options);} else {swalOptions = $.extend(swalOptions, {text: options});}swal(swalOptions, function (isConfirm) {setTimeout(function () {if (isConfirm) {resolve(isConfirm);} else {reject(isConfirm);}}, 100);});});return prom;};window.mprompt = function (options) {var prom = new Promise(function (resolve, reject) {var swalOptions = {title: "",text: "Write something interesting:",type: "input",showCancelButton: true,closeOnConfirm: false,confirmButtonText: "确认",cancelButtonText: "取消",inputPlaceholder: "Write something"};if (typeof(options) == 'object') {swalOptions = $.extend(swalOptions, options);} else {swalOptions = $.extend(swalOptions, {text: options});}swal(swalOptions, function (inputValue) {if (inputValue === false || inputValue === "") return false;swal.close();setTimeout(function () {resolve(inputValue);}, 100);});});return prom;};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript