【发布时间】:2026-02-12 06:25:01
【问题描述】:
test.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<script type="module" src="main.js"></script>
</body>
</html>
辅助.js
export let greeting = 'hello';
main.js
import { greeting } from './auxiliary.js';
document.write(greeting);
在 Web 控制台中有 2 个警告:
- 跨域请求被阻止:同源策略不允许读取位于 ... 的远程资源(原因:CORS 请求不是 http)。
- 此文档中不允许使用模块源 URI:...。
问候语未显示在页面上。
编辑: 根据 areallytinydot 和 Abhinav Nigam 的建议,我在 import 语句中添加了花括号。警告仍然存在,页面仍然是空白的。
【问题讨论】:
标签: javascript html import module export