fileChange(el) {
if (!el.target.files[0].size) return;
// this.fileList(el.target);
let file = el.target.files[0];
let oFReader = new FileReader();
oFReader.readAsDataURL(file);
oFReader.onload = function(oFREvent) {
// console.log(oFREvent.target.result); //base64
this.upImgLUrl = oFREvent.target.result;
};
el.target.value = ''
console.log(this.upImgLUrl);
},
这里怎么把oFREvent.target.result传出去到全局?
console.log(this.upImgLUrl);打印出来是空
你后边 console.log(this.upImgLUrl);肯定打印不出来的,首先oFReader.onload 你可以把它看做是一个异步事件,在外面直接获取是获取不了onload 里面的赋值的,你可以在onload 里面赋值后调用函数把oFREvent.target.result传给函数,然后在函数里面获取