Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <template>
  2. <form action="#" @submit.prevent="submitForm">
  3. <div class="form-group">
  4. <label for="my-input">Text</label>
  5. <input
  6. id="my-input"
  7. class="form-control"
  8. type="file"
  9. ref="fileUpload"
  10. @change="handleFileUpload"
  11. />
  12. </div>
  13. <button type="submit">send</button>
  14. </form>
  15. </template>
  16.  
  17.  
  18. <script>
  19. import axios from 'axios'
  20. export default {
  21. name: 'UploadFile',
  22. props: {
  23. param: String,
  24. message: String,
  25. },
  26.  
  27. data() {
  28. return {
  29. form: {
  30. file: null,
  31. _params: this.param,
  32. },
  33. }
  34. },
  35. methods: {
  36. handleFileUpload() {
  37. console.log('here file upload', this.$refs.fileUpload.files[0])
  38. this.form.file = this.$refs.fileUpload.files[0]
  39. },
  40. submitForm() {
  41. let formData = new FormData()
  42. formData.append('file', this.form.file)
  43. formData.append('_params', this.param)
  44. axios
  45. .post('/!/Form/create', formData, {
  46. headers: {
  47. 'Content-Type': 'multipart/form-data',
  48. },
  49. })
  50. .then(function() {
  51. console.log('SUCCESS!!')
  52. })
  53. .catch(function() {
  54. console.log('FAILURE!!')
  55. })
  56. },
  57. },
  58. }
  59. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement