首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我很难将dat.gui导入javascript

我很难将dat.gui导入javascript
EN

Stack Overflow用户
提问于 2022-09-06 04:33:27
回答 1查看 32关注 0票数 0

我似乎无法将dat.gui导入javascript;

我在用

代码语言:javascript
复制
import * as dat from 'dat.gui';

const gui = new dat.GUI();

当我运行我的代码时,会出现一个错误,它声明: Uncaught :无法在模块外使用导入语句。我尝试过在脚本中添加type=‘end’,但是它最终无法工作。我想知道是否有人遇到过同样的问题,并能帮助我,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-09-06 04:38:23

加载库后,您可以通过window.dat或简单的dat访问它。

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>dat.gui Example</title>
</head>
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.9/dat.gui.min.js" integrity="sha512-WoO4Ih0CDOSLYafy22wZD/mcJ7k0ESLqtQsFa6zFKnEUrbtuGU+GkLtVhgt93xa2qewG5gKEC6CWlN8OaCTSVg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
  <script>
    if(dat != null) {
      alert("dat is working!");
      const gui = new dat.GUI(); 
      if(gui != null) {
            alert("gui is working too!");
      }
    }
  </script>
</body>
</html>

当您使用NodeJS时,您可以使用import (ES6)或require (CommonJS)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73616744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档