方法一:react16以后的版本增加异常捕获
componentDidCatch(error, info) {
const isNewError = (error.toString() !== this.state.prevError.toString());// should only run once
if (isNewError) {//判断两次错误不一致才再次执行,不然一直循环
this.logErrorToMyService(error, info);
this.setState({ prevError: error });
}
}
componentDidCatch(