Reactjs 如何在SPFx中实现ComponentDidCatch
有人能告诉我如何在SPFx中实现ComponentDidCatch吗。我在ReactJs中成功地做到了如下: 引发错误: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({
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?