Skip to content

Instantly share code, notes, and snippets.

@lewiswalsh
Last active May 27, 2022 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewiswalsh/e9af126b872e2f0c85802691095bb5a3 to your computer and use it in GitHub Desktop.
Save lewiswalsh/e9af126b872e2f0c85802691095bb5a3 to your computer and use it in GitHub Desktop.
Upload on file change with Vue #vue
<input type="file" @change="previewFiles" ref="imagefile">
methods: {
previewFiles(event) {
const fileToUpload = this.$refs.imagefile.files[0];
const formData = new FormData();
formData.append('fileToUpload', fileToUpload);
this.$http.post(`url/to/upload/script`, formData)
.then((res) => {
...
})
.catch((err) => { ... });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment