fix(Image): failed to hide loading when using lazy-load (#10193)

This commit is contained in:
neverland 2022-01-15 21:11:11 +08:00 committed by GitHub
parent 6e27d02404
commit be2a401d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ import {
ref, ref,
watch, watch,
computed, computed,
nextTick,
onBeforeUnmount, onBeforeUnmount,
defineComponent, defineComponent,
getCurrentInstance, getCurrentInstance,
@ -159,8 +160,17 @@ export default defineComponent({
}; };
const onLazyLoaded = ({ el }: { el: HTMLElement }) => { const onLazyLoaded = ({ el }: { el: HTMLElement }) => {
if (el === imageRef.value && loading.value) { const check = () => {
onLoad(); if (el === imageRef.value && loading.value) {
onLoad();
}
};
if (imageRef.value) {
check();
} else {
// LazyLoad may trigger loaded event before Image mounted
// https://github.com/youzan/vant/issues/10046
nextTick(check);
} }
}; };