I have the following component property (it's basically for a bootstrap alert component):
props: {
alertType: {
validator: function (value) {
return [ "success", "info", "warning", "danger" ].indexOf(value) >= 0;
},
default: "danger"
},
// Some more things
computed: {
classes: { //Compute the correct classes for the alert type
var classesObj ={
'alert-dismissible': this.dismissable
};
classesObj["alert-"+this.alertType]=true; //Problem if invalid
return classesObj;
}
}
This works well in the sense that if I don't provide an alert type it uses "danger", however if I do provide an alert type and it does not pass validation then the alertType is set to that value and a console warning is emitted (which as I understand is the intended behaviour).
My question is whether it's possible within the classes computed property to determine whether the alertType prop passed or failed validation (and ideally if it failed get and use the default value, based on the component prop definition.