0

I am using javascript FileReader() in Vue.js now. but something problem. when i printed that "this.currentUrl" in onload function, it returns very well. but out of load functions, it returns blank! what's the problem? and how can i fix it ㅠㅠ??

 data: function () {
      return {
          currentUrl: ''
      }
  },
  
 addImages() {
          var reader = new FileReader();

          reader.onload = (e) => {
            this.currentUrl = reader.result
            console.log(this.currentUrl)
            /* it returns well */
          }
          console.log(this.currentUrl);
          /* it returns blank */ 
          reader.readAsDataURL(event.target.files[0])
      },

Thank you

jieun
  • 27
  • 4

1 Answers1

0

onload event of FileReader returns results asynchronously.

guest271314
  • 1
  • 15
  • 104
  • 177