I need a solution that applies a gradient background to the parent div
in case an image fails to load. I've attempted to create a directive for this purpose:
export default {
bind(el: any, binding: any) {
try {
.....
img.onerror = () => {
el.parentNode.classList.add("fallback");
};
} catch (e) {
}
},
};
The directive works with the following template:
<div><img v-image-fallback :src="xxx" /></div>
And it also includes these styles:
.fallback {
width: 600px;
height: 400px;
margin: auto;
background: radial-gradient(...);
}
Is there a way to effectively combine the directive and CSS components together? Can the two work seamlessly?