首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React中未定义Render json

React中未定义Render json
EN

Stack Overflow用户
提问于 2017-08-16 15:50:23
回答 1查看 1.1K关注 0票数 0

有人能在react-js上下文中向我解释以下场景:我与webpack一起工作,并使用预设"babel-preset-env“和"react”。

在一个文件的顶部,我导入了一个config.json,并尝试使用开发人员工具和调试器语句来检查它。

console.log会按预期记录一个对象数组。如果我进入developer-tools js-console并输入ReferenceError,我会得到一个未捕获的配置: CONFIG is not defined。

代码语言:javascript
复制
import React, { Component } from 'react';
import CONFIG from './config.json';

class MyComponent extends Component{
    render(){
        //this statement logs as expected
        console.log(CONFIG);

        // the debugger stops execution, but when I enter CONFIG in the
        // dev-tools Console I get the error: Uncaught ReferenceError: 
        // CONFIG is not defined
        debugger;
    }
}

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-16 15:59:16

CONFIG在您正在编写的模块中定义。它不是一个真正的全局变量,它只是模块(即那个文件)中的“全局”变量。

如果你真的想让它在浏览器中全局可用,可以尝试添加window.CONFIG = CONFIG

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45707957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档