[英]Using Sweet Alert as a window.confirm
I am having trouble finding a way to use sweet alert as a promise to resolve a possilble case here is what i'm trying to to do我很难找到一种使用甜蜜警报作为解决可能案例的承诺的方法,这就是我正在尝试做的
function void continueOn(){
return swal({
title: "Continue?",
text: "Do you want to continue?",
icon: "warning",
buttons: ["no","yes"],
}).then((result) => { return result})
}
return (
<Button
onclick={() => {
if(!doContinue || continueOn()){
console.log("Here")
}
}}
)
What is happening is when it hits continueOn() it just truly does continue on before the user can even answers if they want to continue or not.发生的事情是,当它点击 continueOn() 时,它确实会继续,然后用户甚至可以回答他们是否要继续。 I do want to check if they are in doContinue Mode before I ask them directly.在我直接询问他们之前,我确实想检查他们是否处于 doContinue 模式。 So order does matter.所以顺序很重要。
Check out this example code:查看此示例代码:
const doContinue = false; const continueOn = () => { return swal({ title: "Continue?", text: "Do you want to continue?", icon: "warning", buttons: ["no","yes"], }) } class App extends React.Component { render() { return ( <button onClick={() => { if(!doContinue){ continueOn() .then(result => { // Here do what you want console.log(result) }) } else{ console.log("Popup not shown") } }} >Continue</button> ); } } ReactDOM.render( <App />, document.getElementById("react") );
<div id="react"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.