Last active
September 9, 2017 05:28
-
-
Save martinyung/04efe33be027cc8246ea366886026f28 to your computer and use it in GitHub Desktop.
[blogging purpose] file upload vuejs component - js
This file contains 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
<script> | |
const BASE_URL = "[YOUR_PROJECT_URL]" | |
export default { | |
name: 'FileUpload', | |
directives: { | |
uploader: { | |
bind (el, binding, vnode) { | |
el.addEventListener('change', e => { | |
vnode.context.file = e.target.files[0] | |
}) | |
} | |
} | |
}, | |
methods: { | |
selectFile () { | |
this.$refs.file.click() | |
}, | |
uploadFile () { | |
let formData = new FormData() | |
formData.append('file', this.file) | |
this.$http.post(BASE_URL + '/upload', formData, { | |
before: request => { | |
this.request = request | |
} | |
}) | |
} | |
}, | |
data () { | |
return { | |
file: '' | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment