我使用MEAN堆栈,nodemonParcel。每次我编辑前端代码时,axios返回net::ERR_CONNECTION_REFUSED,并且我需要重新加载页面1-3次以避免此错误。是什么原因造成的?

这是我的请求代码:

 componentDidMount(){
    Axios.get('http://localhost:5000/')
      .then((res) => {
        let newState = Object.assign({}, this.state);
        newState.taskList = res.data;
        this.setState(newState);
      });
  }

最佳答案

您可以使用邮递员之类的工具测试呼叫,该错误可以从您的服务器提供,您还可以获取更多信息并捕获该错误,例如

 Axios.get('http://localhost:5000/')
  .then((res) => {
    let newState = Object.assign({}, this.state);
    newState.taskList = res.data;
    this.setState(newState);
  })
  .catch((err)=>console.log(err));

10-08 17:41