我收到错误"找不到变量上传图像异步">
uploadImageAsync = async (uri) => {
console.log("In upload image asnyc!");
}
这就是我称之为它的地方。
_handleImagePicked = async pickerResult => {
let uploadResponse, uploadResult;
this.setState({ uploading: true });
if (!pickerResult.cancelled) {
uploadResponse = await uploadImageAsync(pickerResult.uri);
uploadResult = await uploadResponse.json();
this.setState({ image: uploadResult.location });
}
this.setState({ uploading: false });
};
我该如何解决这个问题?
到目前为止,我已经尝试过:
async function uploadImageAsync(uri) {
我也试过:
async uploadImageAsync(uri) {
如果在同一组件中定义了uploadImageAsync
函数,则需要调用 this.uploadImageAsync
。
否则,您必须从其他模块import
它
或在同一文件中定义组件外部的函数。