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,10 +160,19 @@ export default defineComponent({
}; };
const onLazyLoaded = ({ el }: { el: HTMLElement }) => { const onLazyLoaded = ({ el }: { el: HTMLElement }) => {
const check = () => {
if (el === imageRef.value && loading.value) { if (el === imageRef.value && loading.value) {
onLoad(); onLoad();
} }
}; };
if (imageRef.value) {
check();
} else {
// LazyLoad may trigger loaded event before Image mounted
// https://github.com/youzan/vant/issues/10046
nextTick(check);
}
};
const onLazyLoadError = ({ el }: { el: HTMLElement }) => { const onLazyLoadError = ({ el }: { el: HTMLElement }) => {
if (el === imageRef.value && !error.value) { if (el === imageRef.value && !error.value) {