Arrays window.enableMouseFlow在componentDidMount()中未定义,但在render()中可用

Arrays window.enableMouseFlow在componentDidMount()中未定义,但在render()中可用,arrays,reactjs,ecmascript-6,react-redux,Arrays,Reactjs,Ecmascript 6,React Redux,嗨,我有这段代码 export class CompanyAccountsList extends Component { constructor(props) { super(props); } getChildContext() { return { prefix: 'company_accounting' }; } componentDidMount(

嗨,我有这段代码

    export class CompanyAccountsList extends Component {
        constructor(props) {
            super(props);
        }

        getChildContext() {
            return { prefix: 'company_accounting' };
        }

        componentDidMount() {
            //getting window.enableMouseFlow in this console
            console.log(window);

            //can't get window.enableMouseFlow in this console
            console.log(window.enableMouseFlow);

            if (window.enableMouseFlow) {
                //This codes are never executing as the condition is undefined
                enableMouseFlow();
                setMouseFlowTag('new_company_accounting');
            }
        }

        render() {
    //Rendering codes are here
    }
在初始加载页面时,我得到的结果如下

Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …} CompanyAccountsList.jsx?a48a:36
undefined
在控制台的“窗口对象”中,“enableMouseFlow”可用,但当我尝试将其作为console.log(window.enableMouseFlow)获取时;令人欣慰的是,“未定义”

如果我在render()方法中对其进行控制台操作,则得到的结果如下:

ƒ () {
          sessionStorage.setItem('mf_start', '1');
          activateMouseflow();
      }

总之,我在componentDidMount()中找不到'window.enableMouseFlow',

我认为
console.log
正在传递一个对window的引用,因此它可能在实际记录到控制台时被解析。 你可以试试

const x=JSON.stringify(窗口);
控制台日志(x)
(我想这会给你在组件安装时的窗口)


但我猜enablemouseflow是在其他脚本中创建页面后添加到
窗口中的东西,因此它实际上不适用于此组件。(但将在渲染时可用)。

@Alan是的,实际上我正在componentDidMount中获取窗口,即使我在控制台窗口中也可以在控制台中获取enableMouseFlow

console.log(window);

Output: 
//window.enableMouseFlow is available
但如果我只是控制台window.enableMouseFlow,我会认为它是未定义的

console.log(window.enableMouseFlow);

Output:
//Undefined
////window.enableMouseFlow is not available
其次,是的,我的想法和您一样,在其他脚本中创建页面后,enablemouseflow将被添加到窗口中,但我有一些其他类似的reactJs页面,可以在componentDidMount中获取console.log(window.enablemouseflow)

仅供参考,在浏览器控制台中填充页面后,我可以获得console.log(window.enableMouseFlow)

实际上,window.enablemouseflow加载得稍晚一些。实际上,请参见屏幕截图:

嗯。。。所以,我们对正在发生的事情达成了一致。稍后将加载window.enableMouseFlow(可能在该组件的同级组件中,而其他组件可能将该enableMouseFlow启用码作为其父组件,这就是为什么它会出现在它们的构造函数中)。这似乎是您想对
窗口执行的任何操作。enableMouseFlow
您可以在
render()中执行。
否?