【发布时间】:2016-06-10 11:56:19
【问题描述】:
如果可能的话,我想要以下内容,但使用一行:
import Module from './Module/Module;'export Module;
我尝试了以下方法,但似乎不起作用:
export Module from './Module/Module;
【问题讨论】:
标签: react-native ecmascript-6 import
如果可能的话,我想要以下内容,但使用一行:
import Module from './Module/Module;'export Module;我尝试了以下方法,但似乎不起作用:
export Module from './Module/Module;【问题讨论】:
标签: react-native ecmascript-6 import
export {default as Module} from './Module/Module';
是标准的 ES6 方式,只要您不需要 Module 也可以在执行导出的模块内使用。
export Module from './Module/Module';
是一种提议的 ESnext 方法,但仅当您现在在 Babel 中启用它时才有效。
【讨论】:
component 现在是只读的,无法热重新加载。很奇怪!
export-extensions - babeljs.io/docs/plugins/transform-export-extensions
export { default as default } from 或 export { default } from
我不知道为什么,但这对我有用:
组件/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/'
【讨论】:
所以,我发现这对于在 components 目录的根目录下有一个 index.js 以便于引用的即时导出功能非常有效:
import Component from './Component/Component'
import ComponentTwo from './ComponentTwo/ComponentTwo'
module.exports = {
Component,
ComponentTwo
};
您需要使用module.exports。
【讨论】:
Component 将不再是对导出组件的引用,而是一个对象,您的实例引用位于 Component.default
module.exports 的情况下执行此操作吗?我喜欢这种将一堆组件打包成index.js 的方法,但无法弄清楚语法。 import x from 'x'; import y from 'y'; export default {x, y}; 然后 import {x} from xy; 不起作用(我不知道为什么不)
export {x, y}吗?