mirror of
https://github.com/koel/koel
synced 2024-12-22 18:43:21 +00:00
13 lines
459 B
TypeScript
13 lines
459 B
TypeScript
|
import { Directive } from 'vue'
|
||
|
|
||
|
export const hideBrokenIcon: Directive = {
|
||
|
mounted: async (el: HTMLImageElement) => {
|
||
|
el.addEventListener('error', () => (el.style.visibility = 'hidden'))
|
||
|
|
||
|
// For v-bind, an empty source e.g. :src="emptySrc" will NOT be rendered
|
||
|
// and the error event will not be triggered.
|
||
|
// We'll work around by explicitly setting the src to an empty string, which will trigger the error.
|
||
|
el.src = el.src || ''
|
||
|
}
|
||
|
}
|