import:* 的方式,请问这个是什么意思呢?
我们知道在ESM中可以定义模块:
export default {
a: 1,
b: 2,
c: () => 3
};
export const d = 4;
export const e = 5;
引用时候:
import others, { e } from './others';
// 1.import others 【引入export default】引入后可用: others.a others.b others.c
// 2.import { e } 【引入export】
今天看到一种引入:* 的方式,请问这个是什么意思呢?
import * as path from "path";
回复
1个回答

test
2024-07-12
就是把所有的 export const
暴露出来的属性和方法都整合到 path
这个变量下,就可以通过 path.d
、path.e
去调用了(不包括 export default
暴露出来的属性和方法)。
可以算是比较基础的 ESM
引入的语法了。
参考文档
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容