Skip to content

Instantly share code, notes, and snippets.

@NiltonMorais
Created October 4, 2017 00:41
Show Gist options
  • Select an option

  • Save NiltonMorais/7366bee920da646a750432c4d6e0d1e3 to your computer and use it in GitHub Desktop.

Select an option

Save NiltonMorais/7366bee920da646a750432c4d6e0d1e3 to your computer and use it in GitHub Desktop.
Component com formulário de exemplo para upload de arquivo com vuejs 2: https://portal.code.education/admin/curso/duvidas/5246/view
<template>
<div class="container">
<form method="POST" @submit.prevent="send()">
<label>Arquivo</label>
<input @change="setFile" type="file">
<button type="submit" class="btn">Enviar</button>
</form>
</div>
</template>
<script type="text/javascript">
export default {
data() {
return {
file: null
}
},
methods: {
setFile(e) {
var files = e.target.files;
this.file = files[0];
},
send() {
let data = new FormData();
data.append('file', this.file);
this.$http.post('teste', data, {
headers: {'Content-type': 'multipart/form-data'}
});
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment