我try 将用于定制标准alert 框的Sweet Alert 2个Java脚本库集成到一个Rails7应用程序中,但我收到了以下error message: "Swal is not defined." 我使用的是Ruby 3和rails 7.
我最初try 在我的Rails应用程序中使用"sweet-alert2-rails"gem,但目前没有可用的更新.因此,我try 使用导入映射来完成此任务,并通过运行以下代码行来完成此任务.
bin/importmap pin sweetalert2
最重要的是,我将下面的行添加到application.js
import Swal from "sweetalert2"
当我try 在我的view files中使用"甜蜜警示2"时,我遇到了上述问题.
Swal.fire(
'Good job!',
'You clicked the button!',
'success'
)
为了将Sweet Alerts集成到我的Rails应用程序中,我使用了以下链接.