您可以尝试以下解决方案来解决此问题:
检查您的API端点是否正确。
确保您的API端点返回正确的JSON数据。
使用“then”和“catch”处理Axios返回的数据,例如:
axios.get('/api/some-data') .then(response => { console.log(response.data); }) .catch(error => { console.log(error); });
app.use(cors({ origin: 'http://localhost:3000', optionsSuccessStatus: 200 }));
axios.get('/api/some-data', { responseType: 'text' }) .then(response => { console.log(response.data); }) .catch(error => { console.log(error); });
使用上述方法,您应该能够解决Axios返回垃圾值的问题。
上一篇:Axios返回空字符串值