小编典典

反应:Axios网络错误

reactjs

这是我第一次使用axios,遇到错误。

  axios.get(
    `http://someurl.com/page1?param1=1&param2=${param2_id}`
  )
  .then(function(response) {
    alert();
  })
  .catch(function(error) {
    console.log(error);
  });

使用正确的url和参数,当我检查网络请求时,确实可以从服务器中获得正确的答案,但是当我打开控制台时,我看到它没有调用回调,而是捕获了错误。

错误:网络错误堆栈跟踪:createError @ http:// localhost:3000 / static / js /
bundle.js:2188:15

handleError @ http:// localhost:3000 / static / js /
bundle.js:1717:14


阅读 625

收藏
2020-07-22

共1个答案

小编典典

如果使用NodeJS创建API


您的Express应用程序需要使用CORS(跨源资源共享)。将以下内容添加到您的服务器文件中:

// This should already be declared in your API file
var app = express();

// ADD THIS
var cors = require('cors');
app.use(cors());

为了更全面地了解CORS,请阅读有关CORSMozilla文档

2020-07-22