feat: branch upload image preview

This commit is contained in:
Methapon2001 2024-04-17 13:51:47 +07:00
parent 981f779e1e
commit 5c1cc88a48

View file

@ -16,14 +16,23 @@ import { useI18n } from 'vue-i18n';
import BranchCard from 'src/components/01_branch-management/BranchCard.vue';
const profileFile = ref<File | undefined>(undefined);
const imageUrl = ref<string | null>();
const inputFile = (() => {
const element = document.createElement('input');
element.type = 'file';
element.accept = 'image/*';
const reader = new FileReader();
reader.addEventListener('load', () => {
if (typeof reader.result === 'string') imageUrl.value = reader.result;
});
element.addEventListener('change', () => {
profileFile.value = element.files?.[0];
if (profileFile.value) {
reader.readAsDataURL(profileFile.value);
}
});
return element;