-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.vue
50 lines (42 loc) · 1.12 KB
/
upload.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<template>
<div>
<small>Change/Upload</small>
<input type="file" @change="onFileChange">
<button class="btn btn-success btn-xs" @click="upload">Upload</button>
</div>
</template>
<script>
export default {
props: ['any_props'],
data() {
return {
image: '',
file: null
}
},
methods: {
onFileChange(e) {
let files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
this.createImage(files[0]);
},
createImage(file) {
let reader = new FileReader();
let vm = this;
reader.onload = (e) => {
vm.image = e.target.result;
};
reader.readAsDataURL(file);
},
upload(){
axios.post('/path/to/url', {image: this.image}).then(response => {
alert('Uploaded');
});
}
}
}
</script>
<style>
/* any styles */
</style>