mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
fix(Uploader): render objectUrl to avoid perf issue (#12051)
* fix(Uploader): render objectUrl to avoid perf issue * fix: test case
This commit is contained in:
parent
98d1a430e4
commit
a789418366
@ -168,6 +168,7 @@ export default defineComponent({
|
||||
file,
|
||||
status: '',
|
||||
message: '',
|
||||
objectUrl: URL.createObjectURL(file),
|
||||
};
|
||||
|
||||
if (contents[index]) {
|
||||
@ -185,6 +186,7 @@ export default defineComponent({
|
||||
file: files as File,
|
||||
status: '',
|
||||
message: '',
|
||||
objectUrl: URL.createObjectURL(files as File),
|
||||
};
|
||||
|
||||
if (content) {
|
||||
@ -240,8 +242,8 @@ export default defineComponent({
|
||||
const imageFiles = props.modelValue.filter(isImageFile);
|
||||
const images = imageFiles
|
||||
.map((item) => {
|
||||
if (item.file && !item.url && item.status !== 'failed') {
|
||||
item.url = URL.createObjectURL(item.file);
|
||||
if (item.objectUrl && !item.url && item.status !== 'failed') {
|
||||
item.url = item.objectUrl;
|
||||
urls.push(item.url);
|
||||
}
|
||||
return item.url;
|
||||
|
@ -114,7 +114,7 @@ export default defineComponent({
|
||||
<Image
|
||||
v-slots={{ default: renderCover }}
|
||||
fit={imageFit}
|
||||
src={item.content || item.url}
|
||||
src={item.objectUrl || item.content || item.url}
|
||||
class={bem('preview-image')}
|
||||
width={Array.isArray(previewSize) ? previewSize[0] : previewSize}
|
||||
height={Array.isArray(previewSize) ? previewSize[1] : previewSize}
|
||||
|
@ -8,6 +8,7 @@ export type UploaderResultType = 'dataUrl' | 'text' | 'file';
|
||||
export type UploaderFileListItem = {
|
||||
url?: string;
|
||||
file?: File;
|
||||
objectUrl?: string;
|
||||
content?: string;
|
||||
isImage?: boolean;
|
||||
status?: '' | 'uploading' | 'done' | 'failed';
|
||||
|
@ -59,6 +59,9 @@ export async function mockScrollTop(value: number) {
|
||||
return nextTick();
|
||||
}
|
||||
|
||||
// js-dom do not implement `URL.createObjectURL`
|
||||
global.URL.createObjectURL = jest.fn();
|
||||
|
||||
mockScrollIntoView();
|
||||
mockHTMLElementOffset();
|
||||
mockGetBoundingClientRect({
|
||||
|
Loading…
x
Reference in New Issue
Block a user