split files
This commit is contained in:
parent
62f8991e11
commit
9e3a6721c9
7 changed files with 99 additions and 123 deletions
29
public/components/Upload.vue.js
Normal file
29
public/components/Upload.vue.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const Upload = {
|
||||
name: 'upload',
|
||||
props: {
|
||||
accept: String,
|
||||
label: String,
|
||||
},
|
||||
template: `
|
||||
<label>
|
||||
<input type="file" style="display: none" @change="upload" :accept="accept" />
|
||||
<span class="btn">{{label || 'Upload File'}}</span>
|
||||
</label>
|
||||
`,
|
||||
methods: {
|
||||
async upload(evt) {
|
||||
const file = evt.target.files[0]
|
||||
if (!file) return;
|
||||
const formData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
const res = await fetch('/upload', {
|
||||
method: 'post',
|
||||
body: formData,
|
||||
})
|
||||
const j = await res.json()
|
||||
this.$emit('uploaded', j)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default Upload
|
||||
Loading…
Add table
Add a link
Reference in a new issue