feat: emit event when in headless mode
This commit is contained in:
parent
d9f6e1423a
commit
ac1e8f71e9
1 changed files with 7 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
import AppBox from './app/AppBox.vue';
|
import AppBox from './app/AppBox.vue';
|
||||||
|
|
||||||
defineExpose({ browse });
|
defineExpose({ browse });
|
||||||
|
|
@ -8,7 +9,7 @@ defineProps<{
|
||||||
hiddenFooter?: boolean;
|
hiddenFooter?: boolean;
|
||||||
defaultUrl?: string;
|
defaultUrl?: string;
|
||||||
}>();
|
}>();
|
||||||
defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'save', file: File | null, url: string | null): void;
|
(e: 'save', file: File | null, url: string | null): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
|
@ -36,6 +37,7 @@ const inputFile = (() => {
|
||||||
_element.addEventListener('change', change);
|
_element.addEventListener('change', change);
|
||||||
return _element;
|
return _element;
|
||||||
})();
|
})();
|
||||||
|
const headless = ref(false);
|
||||||
|
|
||||||
reader.addEventListener('load', () => {
|
reader.addEventListener('load', () => {
|
||||||
if (typeof reader.result === 'string') imageUrl.value = reader.result;
|
if (typeof reader.result === 'string') imageUrl.value = reader.result;
|
||||||
|
|
@ -43,6 +45,7 @@ reader.addEventListener('load', () => {
|
||||||
|
|
||||||
function browse() {
|
function browse() {
|
||||||
inputFile?.click();
|
inputFile?.click();
|
||||||
|
headless.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function change(e: Event) {
|
function change(e: Event) {
|
||||||
|
|
@ -52,7 +55,10 @@ function change(e: Event) {
|
||||||
if (_file) {
|
if (_file) {
|
||||||
file.value = _file;
|
file.value = _file;
|
||||||
reader.readAsDataURL(_file);
|
reader.readAsDataURL(_file);
|
||||||
|
if (headless) emit('save', _file, imageUrl.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headless.value = false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue