0👍
First, add a ref="foo"
to your <input>
tag, you can read more about refs in this link. Then you can add a @change="handleFileUpload()"
to your <input>
tag too.
The handleFileUpload()
will be like this:
handleFileUpload() {
this.file = this.$refs.foo.files[0];
}
Then on your submit function, you’ll have something like this:
let formData = new FormData()
formData.append('file', this.file);
Also, don’t forget to add the Content-Type = multipart/form-data
in your header. This allows the webserver to know that you’re passing a file instead of just key-value pairs.
Source:stackexchange.com