简体   繁体   English

ES6 全局导入

[英]ES6 global import

What is the best way to import some modules in all of the files of the project, so I don't have to write stuff like:在项目的所有文件中导入一些模块的最佳方法是什么,所以我不必写这样的东西:

import React from 'react';
import Reflux from 'reflux';
import reactMixin from 'react-mixin';

in almost every single file?在几乎每个文件中?

The other answer covers this, but not with valid ES6, so I'm adding my own.另一个答案涵盖了这一点,但没有使用有效的 ES6,所以我要添加我自己的。 Make a central file to import your react components, in some central react.js file在一些中央react.js文件中制作一个中央文件来导入你的反应组件

export {default as React} from 'react';
export {default as Reflux} from 'reflux';
export {default as reactMixin} from 'react-mixin';

Then in the files where you need to use these three, you could do然后在需要使用这三个的文件中,你可以这样做

import {React, Reflux, reactMixin} from './react';

to import all three into your component file.将所有三个导入到您的组件文件中。

创建一个声明常见导入的“基础”,然后您可以导入该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM