-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyComponent.vue
55 lines (44 loc) · 1.54 KB
/
MyComponent.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
51
52
53
54
<template>
<div class="container">
<h2>Laravel + Vue - Base64 Image Component</h2>
<form v-on:submit.prevent="save">
<input v-model="my_model.title" placeholder="Title" name="title" type="text">
<input type="file" v-on:change="onFileChange">
<button type="submit">Save</button>
</form>
</div>
</template>
<script>
export default {
data () {
return{
my_model:{
title:'',
image:''
},
}
},
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()
reader.onload = (e) => {
this.my_model.image = e.target.result
};
reader.readAsDataURL(file)
},
save: function(){
axios.post('api/save', this.my_model).then(response => {
console.log(response.data)
}, response => {
console.log(response)
})
},
},
}
</script>