<template>
<div>
<input type="file" id="file" ref="file" v-on:change="handleFileUpload()"/>
<button @click="submitFile">上传</button>
</div>
</template>
<script>
import axios from 'axios';
export default {
data(){
return {
file: ''
}
},
methods: {
submitFile(){
let formData = new FormData();
formData.append('file', this.file);
axios.post( 'http://localhost:8080/upload/photos',
formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(function(){
console.log('SUCCESS!!');
})
.catch(function(){
console.log('FAILURE!!');
});
},
handleFileUpload(){
this.file = this.$refs.file.files[0];
}
}
}
</script>
<style scoped>
.btn_pos{
margin-top: 0px;
}
</style>