通常情况下,Axios.get()返回的结果为Promise对象。如果结果返回undefined,可能是由于以下原因:
async function fetchData() { try { const response = await Axios.get('/api/data'); console.log(response.data); } catch (error) { console.error(error); } } fetchData();
如果使用.then()语法,也要记得处理Promise对象里面的数据或者异常,例如:
Axios.get('/api/data') .then(response => console.log(response.data)) .catch(error => console.error(error));
另外,在请求的URL中,也要确保URL是正确的并且能够返回数据。