【发布时间】:2020-12-06 09:01:28
【问题描述】:
我想在我的 javascript 文件中导入一个模块(在我的例子中是threejs),以便让 vscode 的自动完成功能正常工作。当我使用
import * as THREE from './lib/three'
但导入实际上被 CORS 跨域策略阻止,说同源规则允许从外部源文件读取(因为请求不是 http ?!)。
有人知道解决方法吗?到目前为止,我只能在没有 import 语句的情况下使用模块,因此无法使用自动完成功能。
这是我的代码:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="margin: 0">
<h3>Hello</h3>
<script type="module" src="sketch.js"></script>
</body>
</html>
还有sketch.js
import * as THREE from './lib/three';
const scene = new THREE.Scene();
提前致谢,祝您有美好的一天。 方扎内
【问题讨论】:
标签: javascript import module es6-modules