我收到错误消息“找不到变量uploadImageAsync”
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
或在同一文件中的组件外部定义函数。