2021-09-22 03:57:33 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2022-05-29 18:46:45 +02:00
|
|
|
<input ref="fileInput" type="file" :accept="accept" class="hidden" @change="inputChanged" />
|
2024-04-07 23:24:23 +02:00
|
|
|
<ui-btn @click="clickUpload" color="primary" class="hidden md:block w-full" type="text"><slot /></ui-btn>
|
2022-06-26 18:15:19 +02:00
|
|
|
<ui-icon-btn @click="clickUpload" icon="upload" class="block md:hidden" />
|
2021-09-22 03:57:33 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2021-10-09 00:30:20 +02:00
|
|
|
props: {
|
|
|
|
accept: {
|
|
|
|
type: String,
|
|
|
|
default: '.png, .jpg, .jpeg, .webp'
|
2021-09-22 03:57:33 +02:00
|
|
|
}
|
|
|
|
},
|
2021-10-09 00:30:20 +02:00
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
2021-09-22 03:57:33 +02:00
|
|
|
computed: {},
|
|
|
|
methods: {
|
|
|
|
reset() {
|
|
|
|
if (this.$refs.fileInput) {
|
|
|
|
this.$refs.fileInput.value = ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clickUpload() {
|
|
|
|
if (this.$refs.fileInput) {
|
|
|
|
this.$refs.fileInput.click()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
inputChanged(e) {
|
|
|
|
if (!e.target || !e.target.files) return
|
|
|
|
var _files = Array.from(e.target.files)
|
|
|
|
if (_files && _files.length) {
|
|
|
|
var file = _files[0]
|
|
|
|
this.$emit('change', file)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
|
|
|
</script>
|