如果可能的话,我想要以下内容,但用一行:
import Module from './Module/Module;'
export Module;
我尝试了以下方法,但似乎不起作用:
export Module from './Module/Module;
export {default as Module} from './Module/Module';
是标准的 ES6 方式,只要您不需要
Module
也可以在进行导出的模块内使用。
export Module from './Module/Module';
是建议的 ESnext 方法,但只有在您现在在 Babel 中启用它时才有效。
我不知道为什么,但这对我有用:
组件/index.js:
import 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/'
export {Module as default} from '/path'
这对我有用。
因此,我发现这对于立即导出功能非常有效,在
index.js
目录的根目录下有一个 components
以便于引用:
import Component from './Component/Component'
import ComponentTwo from './ComponentTwo/ComponentTwo'
module.exports = {
Component,
ComponentTwo
};
您需要使用
module.exports
。