根据以下步骤:
1, 首先新建一个 config.JS 文件. 在该文件写以下代码:
- global.constants = {
- website:'http://www.baidu.com/',
- name:'百度',
- };
其中,"constants" 表示名称, 可以随意自己定义名称.
2, 在需要用到这个变量的页面引入 config.JS 文件.
- import './config';class App extends Component {
- render() {
- return (
- <div > 名称:{global.constants.name}</div>
- );
- }}
- export default AddressAdd;
其中, 注意声明的 config,JS 文件存放的位置.
3, 输出结果:
来源: http://www.css88.com/qa/react/14203.html