我想在我的reactJs应用程序中实现Bootbox弹出窗口。
BootBox.Js 链接:- https://bootboxjs.com/examples.html
如果有人已经实现了这种模型, 请分享。
我已经使用警报完成了这个模型弹出窗口
我想将此模型转换为 BootBox.js Popup。
有什么建议吗?
安装 Bootbox.js
npm install bootbox
在 React 组件中导入 Bootbox.js:
import bootbox from 'bootbox';
您可以通过在事件处理程序中调用 Bootbox.js 与 React 组件集成。以下是如何使用 Bootbox.js 作为“否”按钮的示例:
<Button onClick={() => {
bootbox.confirm("Are you sure you want to cancel?", function (result) {
if (result) {
// Handle the "No" action here
setShow(false); // Close the alert or perform any other action
}
});
}} variant="btn btn-danger">No</Button>
当单击“否”按钮时,此代码会显示一个确认对话框。如果用户确认(“否”),它将执行回调函数内的代码,您可以在其中执行必要的操作,例如关闭警报。
您可以类似地将 Bootbox.js 与“是”按钮集成,方法是使用 bootbox.confirm 函数和处理“是”操作的回调函数。