fix: select same image result in image not change

This commit is contained in:
Methapon2001 2024-12-11 13:28:49 +07:00
parent 0bd5b3dcb1
commit 6f9e693c58

View file

@ -52,12 +52,14 @@ const onCreateData = defineModel<{
const apiBaseUrl = import.meta.env.VITE_API_BASE_URL; const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
const reader = new FileReader(); const reader = new FileReader();
const inputFile = (() => { const { inputFile, resetInputFile } = (() => {
const _form = document.createElement('form');
const _element = document.createElement('input'); const _element = document.createElement('input');
_element.type = 'file'; _element.type = 'file';
_element.accept = 'image/*'; _element.accept = 'image/*';
_element.addEventListener('change', change); _element.addEventListener('change', change);
return _element; _form.appendChild(_element);
return { inputFile: _element, resetInputFile: () => _form.reset() };
})(); })();
const selectedImg = ref(''); const selectedImg = ref('');
@ -83,6 +85,7 @@ reader.addEventListener('load', () => {
}); });
function browse() { function browse() {
resetInputFile();
inputFile?.click(); inputFile?.click();
} }
@ -219,11 +222,7 @@ watch(
unelevated unelevated
round round
v-if="!changeDisabled" v-if="!changeDisabled"
@click=" @click="browse"
() => {
inputFile?.click();
}
"
style="color: hsla(var(--stone-0-hsl) / 0.7)" style="color: hsla(var(--stone-0-hsl) / 0.7)"
></q-btn> ></q-btn>
<q-btn <q-btn