forked from AkkomaGang/akkoma-fe
Add MediaUpload component.
This commit is contained in:
parent
dcb7fd1440
commit
a73916dd7f
2 changed files with 39 additions and 0 deletions
22
src/components/media_upload/media_upload.js
Normal file
22
src/components/media_upload/media_upload.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* eslint-env browser */
|
||||||
|
import statusPosterService from '../../services/status_poster/status_poster.service.js'
|
||||||
|
|
||||||
|
const mediaUpload = {
|
||||||
|
mounted () {
|
||||||
|
const store = this.$store
|
||||||
|
const input = this.$el.querySelector('input')
|
||||||
|
const self = this
|
||||||
|
|
||||||
|
input.addEventListener('change', ({target}) => {
|
||||||
|
const file = target.files[0];
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('media', file);
|
||||||
|
statusPosterService.uploadMedia({ store, formData })
|
||||||
|
.then((fileData) => {
|
||||||
|
self.$emit('uploaded', fileData)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default mediaUpload
|
17
src/components/media_upload/media_upload.vue
Normal file
17
src/components/media_upload/media_upload.vue
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<template>
|
||||||
|
<div class="media-upload">
|
||||||
|
<label class="btn btn-default">
|
||||||
|
<i class="fa icon-upload"></i>
|
||||||
|
<input type=file style="position: fixed; top: -100em"></input>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script src="./media_upload.js" ></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.media-upload {
|
||||||
|
font-size: 26px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in a new issue