spl*_*tru 5 javascript ecmascript-6 es6-modules
我有以下代码:
module.exports = {
key: "value",
key2: 1234
}
Run Code Online (Sandbox Code Playgroud)
如果我将其更改为:
export default {
key: "value",
key2: 1234
}
Run Code Online (Sandbox Code Playgroud)
然后以下导入停止工作:
import {key, key2} from 'module.js';
Run Code Online (Sandbox Code Playgroud)
什么是导出对象的 ES6 等价物?
您可以先定义变量并导出它们:
const key = 'value';
const key2 = 1234;
export { key, key2 };
Run Code Online (Sandbox Code Playgroud)
或者您可以在定义它们的同一行中导出它们:
export const key = 'value';
export const key2 = 1234;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1661 次 |
| 最近记录: |