需要确保将POST请求的数据主体正确处理为字符串格式,一般使用JSON.stringify()方法转换,如下所示:
import axios from 'axios';
const data = {
name: 'smalldee',
age: 18
};
axios.post('/api/submit', JSON.stringify(data), {
headers: {
'Content-Type': 'application/json'
}
}).then(res => {
console.log(res);
});