如果可能的话,我希望将以下内容在一行内完成:
import Module from './Module/Module;'
export Module;
我尝试了以下方式,但似乎不起作用:
export Module from './Module/Module;
如果可能的话,我希望将以下内容在一行内完成:
import Module from './Module/Module;'
export Module;
我尝试了以下方式,但似乎不起作用:
export Module from './Module/Module;
export {default as Module} from './Module/Module';
只要您不需要在导出模块内部也使用Module
,那么这是标准的ES6方式。
export Module from './Module/Module';
这是一种建议的 ESnext 实现方式,但目前只有在 Babel 中启用了它才能生效。
export-extensions
,在这里 - http://babeljs.io/docs/plugins/transform-export-extensions/ - Noitidartexport { default as default } from
或 export { default } from
的意思是将默认导出(default export)从一个模块导出。第一个语法可以使用 as
关键字给默认导出起一个别名为 default
,而第二个语法直接将默认导出命名为 default
。 - loganfsmythimport Component from './Component';
import Component2 from './Component2';
import Component3 from './Component3';
import Component4 from './Component4';
export {Component, Component2, Component3, Component4};
我像这样导入输出:
import {Component, Component2, Component3, Component4} from '../components';
export * from './Module/Module';
对于React Native组件,我用这种语法可以工作:
export {default} from 'react-native-swiper';
// Service
// ...
export const paymentService = new PaymentService()
// Entry services/index.js file
export * from './paymentService'
// use it like
import { paymentService } from './services/'
所以,我发现这种方法对于立即导出功能非常有效,只需在components
目录的根目录下有一个index.js
文件,就可以轻松引用:
import Component from './Component/Component'
import ComponentTwo from './ComponentTwo/ComponentTwo'
module.exports = {
Component,
ComponentTwo
};
module.exports
。Component
将不再引用你导出的组件,而是成为一个对象,你的实例引用将在Component.default
上存在。 - Scott Silvimodule.exports
的情况下执行此操作吗?我喜欢使用将一堆组件打包到一个index.js
中的方法,但是无法弄清语法。import x from 'x'; import y from 'y'; export default {x, y};
然后import {x} from xy;
不起作用(我搞不清楚为什么)。 - Alex McMillanexport {x, y}
吗? - jtompl
module.exports = require('./inner.js')
的ES6单行模拟是否存在?和ES6中export { foo as default }
是否有效? - Bergi