Created
June 19, 2019 15:43
-
-
Save chrisvasey/2d06ffca46e7b0c7939535bde04f0cb0 to your computer and use it in GitHub Desktop.
File upload in Vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<input type="file" @change="processFile($event)"> | |
</template> | |
<script> | |
export default { | |
data(){ | |
return { | |
file: null, | |
} | |
}, | |
methods: { | |
processFile(event) { | |
this.form = event.target.files[0]; | |
this.save(); | |
}, | |
save(){ | |
var self = this; | |
var formData = new FormData(); | |
formData.append('file', this.file); | |
axios.post('/test', | |
formData, { | |
headers: { | |
'Content-Type': 'multipart/form-data' | |
} | |
}).then(function (response) { | |
// handle success | |
console.log(response); | |
}) | |
.catch(function (error) { | |
// handle error | |
console.log(error); | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment