Error: A cross-origin error was thrown. React doesn’t have access to the actual error object in deve

在React项目中,有时会看到以下错误:

Error: A cross-origin error was thrown. React doesn’t have access to the actual error object in development. See https://fb.me/react-crossorigin-error for more information.

出现这样的报错信息,先看下自己是否有这样的代码:JSON.parse(xxx) ,多半是这个问题导致的。

对应的处理方式可以采用try catch捕获异常

     try {
        // 可以打断点看执行到这里的时候就已经报错了
        let copyObj = JSON.parse(obj)
        if (copyObj === null) {
          return -
        } else {
          let str = ''
          Object.keys(copyObj).forEach(
            key => (str += key + ': ' + copyObj[key] + ',')
          )
          return str.slice(0, -1)
        }
      } catch (e) {
        message.error('xxxx解析错误')
        return obj
      }

你可能感兴趣的:(react,react)