<template>
<img :src="src" :style="imageStyle" :onerror="onError">
</template>
<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import { string } from 'vue-types'
export default defineComponent({
name: 'ApplicationIcon',
props: {
src: string().def('').isRequired,
defaultImage: string().def('').isRequired
},
setup (props, { emit }) {
const imageStyle = {
backgroundRepeat: 'no-repeat',
backgroundSize: 'contain'
}
// 图片加载失败回调
const onError = () => {
loading.value = false
isLoadError.value = true
// 如何拿到绑定的image对象
// image.src = props.defaultImage
// image.onerror = null
}
return {
imageStyle,
onError
}
}
})
</script>
<style lang="scss" scoped>
</style>
如代码,我想使用img标签和onerror方法使得图片加载失败的时候可以有默认图片,但是我在onerror方法中拿不到image对象,请问我该怎么做?