我遇到了在axios post请求中调用axios的问题。然后方法。
获取以下错误消息:
SyntaxError ...意外的令牌,预期,(145:82)(null)
第145行是调用axios后的.then回调。
这是我的代码:
_handleImagePicked = async pickerResult => {
this.setState({uploading: true})
let uploadResponse, uploadResult;
try {
this.setState({ uploading: true });
if (!pickerResult.cancelled) {
uploadResponse = await uploadImageAsync(pickerResult.uri);
uploadResult = await uploadResponse.json();
this.setState({ image: uploadResult.location });
axios.post( `https://f1cdfd5fa4e.ngrok.io/api/update_photo?email=${this.props.email}&image=${uploadResult.location}`)
.then(response => { this.props.profileUpdate({ prop: 'photo', response.data }) })
.catch(error => console.log(error))
}
} catch (e) {
console.log({ uploadResponse });
console.log({ uploadResult });
console.log({ e });
alert('Upload failed, sorry :(');
} finally {
this.setState({ uploading: false });
}
};
答案 0 :(得分:1)
您正在传递{prop:' photo',response.data}作为回调的参数 但是response.data不能作为密钥添加 尝试发送
this.props.profileUpdate({prop:' photo',data:response.data})