Vue js – Define prop as a specific type

I’m building a vuejs component which accepts a prop by the name of idFieldType

Now I want this prop to accept only a Number Type or a String Type

So I wrote it as follows

idFieldType: {
    Type: Function,
    default: function() {
        return Number;
    },
    validator: function() {
         if(value == String || value == Number) {
               return true;
         }

         return false;    
    }
}

I also tried replacing the type to Object.

My question is how can I write a prop that accepts only specific types ?


Source: stackoverflow-javascript

Leave a Reply

Your email address will not be published. Required fields are marked *