我想部分更新一组数据和一个图像文件。我的图像得到了更新,但其他数据没有被更新。 以下是我的代码示例:
updateUsersData() {
const { gender, phone, address, cityId, image, signature } = this.state;
const fd = new FormData();
fd.append('image', image, image.name);
fd.append('gender', gender);
fd.append('phone', phone);
fd.append('address', address);
fd.append('cityId', cityId);
fd.append('signature', signature);
fd.append('_method', 'PATCH');
API.patch(`users/${this.props.id}`,
fd
)
.then(res => {
})
.catch(err => console.log(err))
}
axios.post()
并且在请求中包含了_method
和PATCH
键。对于 Laravel 来说,这似乎是必需的方法。你不能使用axios.patch()
。 - agm1984