【问题标题】:How can I use orginal javascript Web APIs inside react我如何在反应中使用原始的 javascript Web API
【发布时间】:2017-10-20 11:26:21
【问题描述】:

我通过create-react-app快速创建了一个react app,

当我在 componentDidMount() 中调用 new ImageCapture

componentDidMount() {
    imageCapture = new ImageCapture(track);
}

显示

ReferenceError: imageCapture 未定义

不知道是 eslint 阻止了我的通话还是别的什么

我已经用普通的 JS 测试了这个函数,它可以工作。谢谢大家。

【问题讨论】:

    标签: javascript reactjs ecmascript-6


    【解决方案1】:

    您需要使用const/let/var 声明imageCapture

    在不使用声明的情况下,您将变量定义为全局变量,这将在strict mode 中抛出ReferenceError

    例如

    const imageCapture = new ImageCapture(track)

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 1970-01-01
      • 2020-06-20
      • 2017-12-16
      • 2021-10-02
      • 2011-10-16
      • 2018-11-13
      • 2020-10-09
      • 2015-06-30
      相关资源
      最近更新 更多