【发布时间】:2018-02-10 11:54:47
【问题描述】:
我在 axios 发布请求 .then 方法中调用 axios 时遇到问题。
收到以下错误消息:
SyntaxError ... Unexpected token, expected , (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 });
}
};
【问题讨论】:
标签: reactjs react-native redux axios