Skip to content

Commit

Permalink
fix: test for imgEl before setting src
Browse files Browse the repository at this point in the history
resolves #783
  • Loading branch information
danielroe committed May 31, 2023
1 parent 682b674 commit e5a294e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/runtime/components/nuxt-img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@ export default defineComponent({
const img = new Image()
img.src = mainSrc.value
img.onload = (event) => {
imgEl.value!.src = mainSrc.value
if (imgEl.value) {
imgEl.value.src = mainSrc.value
}
placeholderLoaded.value = true
ctx.emit('load', event)
}
} else {
imgEl.value!.onload = (event) => {
return
}

if (imgEl.value) {
imgEl.value.onload = (event) => {
ctx.emit('load', event)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/components/nuxt-picture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ export default defineComponent({
}

onMounted(() => {
imgEl.value!.onload = (event) => {
ctx.emit('load', event)
if (imgEl.value) {
imgEl.value.onload = (event) => {
ctx.emit('load', event)
}
}
})

Expand Down

0 comments on commit e5a294e

Please sign in to comment.