ES6,如何在一行中导出导入的模块?

时间:2016-02-27 04:42:00

标签: import ecmascript-6

我想要以下内容,但如果可能,请使用一行:

  • import Module from './Module/Module;
  • export Module;

我尝试了以下内容,但它似乎无法运作:

  • export Module from './Module/Module;

7 个答案:

答案 0 :(得分:129)

List<RadioButton> list=new ArrayList<>();
list.add(radio_button);

//get value 
String str=list.get(position).getText();

是标准的ES6方式,只要您不需要export {default as Module} from './Module/Module'; 在导出的模块中也可用。

Module

是一种提议的ESnext方法,但只有在你现在在Babel中启用它时才有效。

答案 1 :(得分:13)

我不知道为什么,但这对我有用:

index.jsx:

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 '../componets/index';

答案 2 :(得分:9)

请注意,您还可以从模块中重新导出所有内容:

export * from './Module/Module';

答案 3 :(得分:4)

对于React Native组件,此语法对我有用:

export {default} from 'react-native-swiper';

答案 4 :(得分:1)

因此,我发现这对于在index.js目录的根目录中components的直接导出功能非常有效,以便于引用:

import Component from './Component/Component'
import ComponentTwo from './ComponentTwo/ComponentTwo'

module.exports = {
  Component,
  ComponentTwo
};

您需要使用module.exports

答案 5 :(得分:0)

// Service
// ...
export const paymentService = new PaymentService()

// Entry services/index.js file
export * from './paymentService'

// use it like
import { paymentService } from './services/'

答案 6 :(得分:-3)

所以,这就是答案!

module.exports.your_module = require("your_module");

就我而言,我需要将所有的React组件捆绑到库中。可以很好地工作并将其打包为webpack中的库。