AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …} AxiosError {message: '网络错误', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}

9 浏览
0 Comments

AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …} AxiosError {message: '网络错误', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}

我正在处理一个项目,前端使用React构建,后端使用Spring,但是我似乎无法通过使用axios连接两者。请记住,后端正常工作(并且我对React并不是很擅长)。

这是我在控制台上收到的错误:

  1. AxiosError {message: '网络错误', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}

    1. code: "ERR_NETWORK"

    2. config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}

    3. message: "网络错误"

    4. name: "AxiosError"

    5. request: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …}

    6. response: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …}

    7. [[Prototype]]: Error

这是我的api.js:

import axios from 'axios';
const api = axios.create({
  baseURL: "https://localhost:8080"
});
export default api;

这是我的App.js:

import './App.css';
import axios from "axios";
import {useEffect, useState} from 'react'
import api from './api.js';
function App() {
  const songs = async () => {
    try{
      const response = await api.get("/songs");
    }
    catch(err) {
      console.error(err);
    }
  };
  return (
             

Taylor的歌曲

); } export default App;

问题出现在我尝试点击“quote-bttn”按钮时。

如果有人知道如何解决这个问题,我会非常感激!

(另外,如果我有任何遗漏的东西,这是完整的代码:https://github.com/vitoriaacarvalho/my-taylor-swift-api/commit/0276222d35aa9a3fda8033f594d9727feded854b")

0