Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/runtime/components/NuxtImg.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
...(!props.placeholder || placeholderLoaded.value)
? { sizes: sizes.value.sizes, srcset: sizes.value.srcset }
: {},
...import.meta.server ? { onerror: 'this.setAttribute(\'data-error\', 1)' } : {},
...attrs,
}))

Expand Down Expand Up @@ -133,6 +132,10 @@
const initialLoad = useNuxtApp().isHydrating
const imgEl = useTemplateRef('imgEl')
onMounted(() => {
if (imgEl.value) {
imgEl.value.addEventListener('error', handleImgError)
}

if (placeholder.value || props.custom) {
const img = new Image()

Expand Down Expand Up @@ -180,6 +183,10 @@
emit('error', event)
}
})

function handleImgError() {
this.setAttribute('data-error', '1')

Check failure on line 188 in src/runtime/components/NuxtImg.vue

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

'this' implicitly has type 'any' because it does not have a type annotation.
}
</script>

<script lang="ts">
Expand Down
Loading