export { name1, name2, …, nameN };
export { variable1 as name1, variable2 as name2, …, nameN };
export let name1, name2, …, nameN; // also var
export let name1 = …, name2 = …, …, nameN; // also var, const
export function FunctionName(){...}
export class ClassName {...}
export default expression;
export default function (…) { … } // also class, function*
export default function name1(…) { … } // also class, function*
export { name1 as default, … };
export * from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;
Export Imported Module
es6 模块的导出方法有如下几种:
注意
export { default } from …;
这一行的default
是指将...
模块的default
值作为当前模块的 default 值导出。当前模块只能有一个default
导出。上述代码会编译报错,因为一个模块只能有一个
default
导出值.这里有一个坑是,如果有一个 中间模块 帮助我们做一些其他模块的整理一并导出的话,其他模块的
default
值会被过滤掉。当我们
import
middleware 模块的时候会得到:所以如果我们得到所有模块的值的话需要变更下 middleware 导出方式。
我们必须显示的声明 想要导出 的模块的值对应 当前模块 的导出值是什么。