var image未在alert中定义:(请帮助,非常感谢!
handleBeforeUpload (file, event) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = (function () {
var f = reader.result;
});
var image = f;
alert(image)
var photo = {uri: image}
答案 0 :(得分:1)
你的f变量在onload函数回调的范围内。在该函数之外定义它,您可以在其中定义读取器变量,因此它将在handleBeforeUpload函数的范围内可用
handleBeforeUpload (file, event) {
var reader = new FileReader();
var photo = null;
reader.readAsDataURL(file);
reader.onload = (function () {
f = reader.result;
photo = { uri: f }
});
}