mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Uploader): preview is slow when sum of images size be bigger (#9961)
This commit is contained in:
parent
fa3444f1c5
commit
bd236e9561
@ -4,6 +4,7 @@ import {
|
|||||||
PropType,
|
PropType,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
ExtractPropTypes,
|
ExtractPropTypes,
|
||||||
|
onBeforeUnmount,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
@ -97,6 +98,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const inputRef = ref();
|
const inputRef = ref();
|
||||||
|
const urls: string[] = [];
|
||||||
|
|
||||||
const getDetail = (index = props.modelValue.length) => ({
|
const getDetail = (index = props.modelValue.length) => ({
|
||||||
name: props.name,
|
name: props.name,
|
||||||
@ -225,7 +227,13 @@ export default defineComponent({
|
|||||||
if (props.previewFullImage) {
|
if (props.previewFullImage) {
|
||||||
const imageFiles = props.modelValue.filter(isImageFile);
|
const imageFiles = props.modelValue.filter(isImageFile);
|
||||||
const images = imageFiles
|
const images = imageFiles
|
||||||
.map((item) => item.content || item.url)
|
.map((item) => {
|
||||||
|
if (item.file && !item.url) {
|
||||||
|
item.url = URL.createObjectURL(item.file);
|
||||||
|
urls.push(item.url);
|
||||||
|
}
|
||||||
|
return item.url;
|
||||||
|
})
|
||||||
.filter(Boolean) as string[];
|
.filter(Boolean) as string[];
|
||||||
|
|
||||||
imagePreview = ImagePreview(
|
imagePreview = ImagePreview(
|
||||||
@ -338,6 +346,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
urls.forEach((url) => URL.revokeObjectURL(url));
|
||||||
|
});
|
||||||
|
|
||||||
useExpose<UploaderExpose>({
|
useExpose<UploaderExpose>({
|
||||||
chooseFile,
|
chooseFile,
|
||||||
closeImagePreview,
|
closeImagePreview,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user