doc: update es6.md, add import assertions (#79)
* feat: add import assertions * update
This commit is contained in:
parent
41b42c17b7
commit
7b46142372
17
docs/es6.md
17
docs/es6.md
@ -706,6 +706,23 @@ new URL('data.txt', import.meta.url)
|
|||||||
|
|
||||||
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
|
Node.js 环境中,`import.meta.url`返回的总是本地路径,即 `file:URL` 协议的字符串,比如 `file:///home/user/foo.js`
|
||||||
|
|
||||||
|
### 导入断言(Import Assertions)
|
||||||
|
<!--rehype:wrap-class=col-span-2-->
|
||||||
|
|
||||||
|
#### 静态导入
|
||||||
|
|
||||||
|
```js
|
||||||
|
import json from "./package.json" assert {type: "json"}
|
||||||
|
// 导入 json 文件中的所有对象
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 动态导入
|
||||||
|
|
||||||
|
```js
|
||||||
|
const json =
|
||||||
|
await import("./package.json", { assert: { type: "json" } })
|
||||||
|
```
|
||||||
|
|
||||||
Generators
|
Generators
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user