A problem encountered in converting pictures to base64?

<input type="file" @change="getFile($event)">

getFile:function(e){
    var base64 = "";
    let file = e.target.files[0];
    let reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function (e) {
        //console.log(e.target.result); 
        base64 = e.target.result;
    }
    console.log(base64); //
}

questions are written in comments


FileReader.onload is asynchronous. When you console.log (base64) , onload hasn't been executed yet


because onload is asynchronous


if Synchronize forcibly recommends es6 promise


console.log (base64);
is written inside onload.
if you need to do something extra after the onload executes successfully, you can use the form of a callback function.
for example:

reader.onload = function (e) {
    base64 = e.target.result;
    console.log(base64)
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b373f3-2c070.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b373f3-2c070.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?