在 .then 回调中反应本机 axios 调用操作不起作用
React native axios calling action inside .then callback not working
我在 axios post 请求 .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 });
}
};
您正在将 { prop: 'photo', response.data } 作为参数传递给回调
但无法将 response.data 添加为键
尝试发送
this.props.profileUpdate({prop: 'photo', data:response.data})
我在 axios post 请求 .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 });
}
};
您正在将 { prop: 'photo', response.data } 作为参数传递给回调 但无法将 response.data 添加为键 尝试发送
this.props.profileUpdate({prop: 'photo', data:response.data})