在Axios PUT请求中设置headers配置选项,使它包含‘Content-Type’并将其值设置为‘application/json’。然后在请求中将对象数据转换为JSON字符串并指定数据类型。以下是示例代码:
axios.put('http://example.com/data', JSON.stringify({data: 'new data'}), {
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
console.log(response.data);
}).catch(error => {
console.log(error);
});
这将确保请求以JSON格式发送,并且所有数据将正确发送到服务器。