mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-30 12:49:45 +08:00
fix(Image): load event not triggered in nuxt3
This commit is contained in:
parent
2c30e7ba68
commit
128972a753
@ -3,6 +3,7 @@ import {
|
|||||||
watch,
|
watch,
|
||||||
computed,
|
computed,
|
||||||
nextTick,
|
nextTick,
|
||||||
|
onMounted,
|
||||||
onBeforeUnmount,
|
onBeforeUnmount,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
getCurrentInstance,
|
getCurrentInstance,
|
||||||
@ -69,7 +70,7 @@ export default defineComponent({
|
|||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const error = ref(false);
|
const error = ref(false);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const imageRef = ref<HTMLElement>();
|
const imageRef = ref<HTMLImageElement>();
|
||||||
|
|
||||||
const { $Lazyload } = getCurrentInstance()!.proxy!;
|
const { $Lazyload } = getCurrentInstance()!.proxy!;
|
||||||
|
|
||||||
@ -156,7 +157,13 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img src={props.src} onLoad={onLoad} onError={onError} {...attrs} />
|
<img
|
||||||
|
ref={imageRef}
|
||||||
|
src={props.src}
|
||||||
|
onLoad={onLoad}
|
||||||
|
onError={onError}
|
||||||
|
{...attrs}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -191,6 +198,15 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In nuxt3, the image may not trigger load event,
|
||||||
|
// so the initial complete state should be checked.
|
||||||
|
// https://github.com/youzan/vant/issues/11335
|
||||||
|
onMounted(() => {
|
||||||
|
if (imageRef.value?.complete) {
|
||||||
|
onLoad();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<div
|
<div
|
||||||
class={bem({ round: props.round, block: props.block })}
|
class={bem({ round: props.round, block: props.block })}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user