Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在SPFx中实现ComponentDidCatch_Reactjs_Spfx - Fatal编程技术网

Reactjs 如何在SPFx中实现ComponentDidCatch

Reactjs 如何在SPFx中实现ComponentDidCatch,reactjs,spfx,Reactjs,Spfx,有人能告诉我如何在SPFx中实现ComponentDidCatch吗。我在ReactJs中成功地做到了如下: 引发错误: throw new Error('I crashed!'); 它会在这里被抓住: componentDidCatch(error, errorInfo) {       // Catch errors in any components below and re-render with error message       this.setState({        

有人能告诉我如何在SPFx中实现ComponentDidCatch吗。我在ReactJs中成功地做到了如下: 引发错误:

throw new Error('I crashed!'); 
它会在这里被抓住:

componentDidCatch(error, errorInfo) {
      // Catch errors in any components below and re-render with error message
      this.setState({
        error: error,
        errorInfo: errorInfo
      })
      // You can also log error messages to an error reporting service here
    } 
但是,当我尝试对SPFx执行相同操作时,在抛出错误时,浏览器控制台中会出现以下错误:

未捕获(承诺中)错误:我崩溃了

有没有办法在SPFx中捕获此错误?

在render()方法中,如果存在Errorinfo,是否返回任何HTML?在render()方法中,如果存在Errorinfo,是否返回任何HTML?