function HelloWorldRestApiCall() {
axios.get('http://localhost:8080/hello-world')
.then((response) => successfulResponse(response))
.catch((error) => errorResponse(error))
.finally(() => console.log("clean-up"))
}
function successfulResponse(response) {
console.log(response)
// setMessage(response.data)
setMessage(response.data)
}
我尝试使用不同的网址,但不起作用。
目前尚不清楚您的情况下 axios 是什么,但我建议尝试以下操作:
import axios from 'axios';
const api = axios.create();
import { api } from 'src/boot/axios';
function HelloWorldRestApiCall() {
api.get('http://localhost:8080/hello-world')
.then((response) => successfulResponse(response))
.catch((error) => errorResponse(error))
.finally(() => console.log("clean-up"))
}
此外,尝试使用路由,以便您从
/hello-world
发出请求,并将 /
重新路由到 http://localhost:8080
作为开发服务器,这会有所帮助。