ES6全球进口 [英] ES6 global import
本文介绍了ES6全球进口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在项目的所有文件中导入一些模块的最佳方式是什么,所以我不必写出如下内容:
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';
几乎每一个文件?
推荐答案
另一个答案涵盖了这一点,但不是有效的ES6,所以我添加了自己的。
制作一个中央文件导入您的反应组件,在一些中央的 reactions.js
文件
The other answer covers this, but not with valid ES6, so I'm adding my own.
Make a central file to import your react components, in some central react.js
file
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.
这篇关于ES6全球进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文