Is it possible to create custom prop types with extended validation for Vue.js props?
In the following example, we have a prop called background
that is currently of type Object. I would like to change this to a custom prop type called Image. The Image prop should require the fields src
and alt
, while other fields are optional.
Current implementation:
export default {
props: {
background: {
type: Object,
src: String,
srcset: String,
alt: String,
title: String,
},
},
};
Desired implementation:
class customPropImage {
// magic ...
}
export default {
props: {
background: Image,
},
};