【问题标题】:sweetalet2 commonJS basic examplesweetalet2 commonJS 基本示例
【发布时间】:2020-12-14 12:46:51
【问题描述】:

我很难做出一个非常简单的 commonJS 用法:

const Swal = require('sweetalert2');

Swal.fire('Hello world!');

这有什么问题?

如果我运行代码,什么都不会发生,也不会抛出任何错误。

【问题讨论】:

    标签: sweetalert2


    【解决方案1】:

    您不能在浏览器/客户端 JavaScript 上使用 require()

    您需要通过在 index.html 中添加以下内容从 jsdelivr CDN 获取 SweetAlert2

    <script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>
    

    然后你就可以运行你的JS了

    Swal.fire('Hello world!');
    

    代码笔: https://codepen.io/ahandsel/pen/QWGrOya

    参考: Client on Node.js: Uncaught ReferenceError: require is not defined

    【讨论】:

      猜你喜欢
      • 2021-05-04
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多