fix(Image): load event missing params (#11406)

This commit is contained in:
neverland 2022-12-23 11:07:40 +08:00 committed by GitHub
parent 8043a9e0fe
commit 0ee41a41a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 5 deletions

View File

@ -96,13 +96,22 @@ export default defineComponent({
} }
); );
const onLoad = (event?: Event) => { const onLoad = (event: Event) => {
if (loading.value) { if (loading.value) {
loading.value = false; loading.value = false;
emit('load', event); emit('load', event);
} }
}; };
const triggerLoad = () => {
const loadEvent = new Event('load');
Object.defineProperty(loadEvent, 'target', {
value: imageRef.value,
enumerable: true,
});
onLoad(loadEvent);
};
const onError = (event?: Event) => { const onError = (event?: Event) => {
error.value = true; error.value = true;
loading.value = false; loading.value = false;
@ -172,7 +181,7 @@ export default defineComponent({
const onLazyLoaded = ({ el }: { el: HTMLElement }) => { const onLazyLoaded = ({ el }: { el: HTMLElement }) => {
const check = () => { const check = () => {
if (el === imageRef.value && loading.value) { if (el === imageRef.value && loading.value) {
onLoad(); triggerLoad();
} }
}; };
if (imageRef.value) { if (imageRef.value) {
@ -206,7 +215,7 @@ export default defineComponent({
onMounted(() => { onMounted(() => {
nextTick(() => { nextTick(() => {
if (imageRef.value?.complete) { if (imageRef.value?.complete) {
onLoad(); triggerLoad();
} }
}); });
}); });

View File

@ -125,7 +125,7 @@ app.use(Lazyload);
| Event | Description | Arguments | | Event | Description | Arguments |
| ----- | ------------------------------ | ------------------- | | ----- | ------------------------------ | ------------------- |
| click | Emitted when image is clicked | _event: MouseEvent_ | | click | Emitted when image is clicked | _event: MouseEvent_ |
| load | Emitted when image loaded | - | | load | Emitted when image loaded | _event: Event_ |
| error | Emitted when image load failed | - | | error | Emitted when image load failed | - |
### Slots ### Slots

View File

@ -151,7 +151,7 @@ app.use(Lazyload);
| 事件名 | 说明 | 回调参数 | | 事件名 | 说明 | 回调参数 |
| ------ | ------------------ | ------------------- | | ------ | ------------------ | ------------------- |
| click | 点击图片时触发 | _event: MouseEvent_ | | click | 点击图片时触发 | _event: MouseEvent_ |
| load | 图片加载完毕时触发 | - | | load | 图片加载完毕时触发 | _event: Event_ |
| error | 图片加载失败时触发 | - | | error | 图片加载失败时触发 | - |
### Slots ### Slots