
通过 unpkg 引入 three.js
您希望通过 unpkg 在没有任何前端框架的情况下导入 three.js。然而,在您的代码中,您在 main.js 中无法识别 THREE。
出现此错误是因为您尚未在 index.html 中正确导入 THREE 模块。要解决此问题,请进行以下更改:
使用 importmap 引入 three.js 模块:
index.html
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.155.0/build/three.module.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
console.log(THREE);
</script>或者,直接在 <script> 标签中导入 three.js 模块:
index.html
<script type="module"> import * as THREE from 'https://unpkg.com/three@0.155.0/build/three.module.js'; console.log(THREE); </script>
现在,您可以在 main.js 中通过以下方式访问 THREE:
main.js
console.log("Hello Three.js");
console.log("js" + THREE);
const scene = new THREE.Scene();以上就是使用 unpkg 导入 three.js 时,为什么在 main.js 中无法识别 THREE?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号