[Vuejs]-Accesing the data from an input button for Vue

0👍

If I don’t misunderstood your question then you could also try like this.

According to its documentation, fileChangedCallback is a callback for when a file is selected, returns a File object and its default value is undefined.
Thus, you could use FileReader() to read the data of the file.

HTML

<upload-btn :fileChangedCallback="getFile"></upload-btn>

JS

data() {
    return {
        myFile: ''
    }
},

methods:  {
    getFile (file) {
          let vm = this
          let reader = new FileReader()

          reader.onload = e => {
              vm.myFile = e.target.result
          }
          reader.readAsDataURL(file)
     }
}

Leave a comment