2019-05-22 14:12:11 +02:00
|
|
|
<template>
|
2019-06-17 17:15:27 +02:00
|
|
|
<div class="root">
|
|
|
|
<figure class="image is-128x128">
|
|
|
|
<img class="is-rounded" v-bind:src="imageSrc">
|
|
|
|
<div class="image-placeholder" v-if="!imageSrc"></div>
|
|
|
|
</figure>
|
|
|
|
|
|
|
|
<b-upload @input="onFileChanged">
|
|
|
|
<a class="button is-primary">
|
|
|
|
<b-icon icon="upload"></b-icon>
|
|
|
|
<span>Click to upload</span>
|
|
|
|
</a>
|
|
|
|
</b-upload>
|
|
|
|
</div>
|
2019-05-22 14:12:11 +02:00
|
|
|
</template>
|
|
|
|
|
2019-06-17 17:15:27 +02:00
|
|
|
<style scoped type="scss">
|
|
|
|
.root {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image {
|
|
|
|
margin-right: 30px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image-placeholder {
|
|
|
|
background-color: grey;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 100%;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
<script lang="ts">
|
2019-06-17 17:15:27 +02:00
|
|
|
import { Component, Model, Vue, Watch } from 'vue-property-decorator';
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class PictureUpload extends Vue {
|
2019-06-17 17:15:27 +02:00
|
|
|
@Model('change', { type: File }) readonly pictureFile!: File;
|
|
|
|
|
|
|
|
imageSrc: string | null = null;
|
|
|
|
|
2019-09-09 11:21:42 +02:00
|
|
|
mounted() {
|
|
|
|
this.updatePreview(this.pictureFile);
|
|
|
|
}
|
|
|
|
|
2019-06-17 17:15:27 +02:00
|
|
|
@Watch('pictureFile')
|
2019-09-09 11:21:42 +02:00
|
|
|
onPictureFileChanged(val: File) {
|
2019-06-17 17:15:27 +02:00
|
|
|
this.updatePreview(val);
|
|
|
|
}
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
onFileChanged(file: File) {
|
2019-06-17 17:15:27 +02:00
|
|
|
this.$emit('change', file);
|
|
|
|
|
|
|
|
this.updatePreview(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
private updatePreview(file?: File) {
|
|
|
|
if (file) {
|
|
|
|
this.imageSrc = URL.createObjectURL(file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.imageSrc = null;
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|