我想部分更新一组数据和一个图像文件。我的图像已更新,但其他数据未更新。这是我的代码示例:
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))
}
我认为该代码对您有用
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');
axios.post(
`users/${this.props.id}`,
fd,
{ headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句