Created
October 4, 2017 00:41
-
-
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
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> | |
| <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