可能这是由于JSONPlaceholder返回的内容不是我们预期的数据格式。可以添加 responseType 属性来告诉 Axios 想要接收的数据格式。例如:
import axios from 'axios';
axios.get('https://jsonplaceholder.typicode.com/posts', { responseType: 'json' })
.then(response => console.log(response.data))
.catch(error => console.log(error));
其中,responseType 属性可以为:'arraybuffer', 'blob', 'document', 'json', 'text', 'stream'。在这里,我们可以设置为 'json'。
这样,如果 JSONPlaceholder 返回的是 JSON 格式的数据,那么 Axios 就可以正常地解析数据,避免了返回乱码的问题。