data: 导入
¥data:
imports
data:
URL 支持使用以下 MIME 类型导入:
¥data:
URLs are supported for importing with the following MIME types:
-
text/javascript
用于 ES 模块¥
text/javascript
for ES modules -
application/json
用于 JSON¥
application/json
for JSON -
application/wasm
用于 Wasm¥
application/wasm
for Wasm
import 'data:text/javascript,console.log("hello!");';
import _ from 'data:application/json,"world!"' with { type: 'json' };
data:
URL 仅解析内置模块的 裸说明符 和 绝对说明符。解析 相对说明符 不起作用,因为 data:
不是 特别计划。例如,尝试从 data:text/javascript,import "./foo";
加载 ./foo
无法解析,因为 data:
URL 没有相对解析的概念。
¥data:
URLs only resolve bare specifiers for builtin modules
and absolute specifiers. Resolving
relative specifiers does not work because data:
is not a
special scheme. For example, attempting to load ./foo
from data:text/javascript,import "./foo";
fails to resolve because there
is no concept of relative resolution for data:
URLs.