Answer the question
In order to leave comments, you need to log in
How to upload a file from a form?
How to upload a file through forms
<template>
<div class="form-avatar">
<label>
<img src="#" alt="Аватар">
<input type="file" v-show="false" @change="fileInput($event)">
</label>
</div>
</template>
<script>
export default {
name: "create",
methods: {
fileInput(event) {
console.log(event.target.files[0])
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
const formData = new FormData()
this.selectedFile = event.target.files[0]
formData.append('myFile', this.selectedFile, this.selectedFile.name)
this.$http.post('http://127.0.0.1:8000/upload', formData).then(response => {
console.log('onUpload file ', formData.length ); // 1
status = response.status;
console.log('status --> ', status)
// get status text
response.statusText;
}, response => {
// error callback
console.log('errror ')
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question