有没有办法从 google 应用程序脚本中引用 sweet alert?

Is there a way to reference sweet alert from google apps script?

我正在将库与 src 属性链接起来,并使用一个函数来调用它,但它不起作用

GS:

function doGet(e) { 
  var params = JSON.stringify(e.parameters) 
  var params2 =JSON.parse(params) 
  cache.put("name", params2.name)
  cache.put("DBID", params2.DBID)
  return HtmlService.createTemplateFromFile("test").evaluate()
}

function include(f1){ 
  return HtmlService.createHtmlOutputFromFile(f1).getContent();
} 

Html:

<head>
  <title>Email form test</title>
  <?!= include("CSS") ?>
</head>
<body>   
   <script src="https://cdn.jsdelivr.net/npm/sweetalert2@8.17.6/dist/sweetalert2.all.js"></script>
   <?!= include('Javascript') ?>
   <button type="button" name="Submit" onclick="javascript:t1();"id="sub1"class="btn btn-white btn-animation-1">Submit</button>

调用库(在上面初始化之后):

<script>
function t1(){
  Swal.fire('Any fool can use a computer');
}
</script>

预期的结果应该是我点击按钮,"any fool can use a computer" 应该会弹出一个 sweet alert 2 框

您不需要在 Apps 脚本中导入和评估 Sweetalert 库 - 您可以像往常一样将其包含在 HTML 文件中,并且 return HTML 输出来自 doGet() 上的文件:

code.gs:

function doGet(e) { 
  // your code here
  return HtmlService.createHtmlOutputFromFile("index");
}

和index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>Email form test</title>
  </head>
  <body>   
   <script src="https://cdn.jsdelivr.net/npm/sweetalert2@8.17.6/dist/sweetalert2.all.js"></script>

   <button type="button" name="Submit" onclick="t1();"id="sub1"class="btn btn-white btn-animation-1">Submit</button>
    <script>
      function t1(){
        Swal.fire('Any fool can use a computer');
      }
    </script>
  </body>
</html>