Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJs how to set prop type to any?

Tags:

vue.js

I have props with defined types but I want the last one of them to accept any kind of value

props: {         Size: String,         Label: String,         Name: String,         value: Any     } 

Hpw can I achieve this?

like image 925
G'ofur N Avatar asked Aug 21 '18 09:08

G'ofur N


People also ask

How do you assign a value to a prop in Vue?

To specify the type of prop you want to use in Vue, you will use an object instead of an array. You'll use the name of the property as the key of each property, and the type as the value. If the type of the data passed does not match the prop type, Vue sends an alert (in development mode) in the console with a warning.

How do you mutate Props in Vue?

Mutating props in Vue is an anti-pattern In Vue, we pass data down the the component tree using props. A parent component will use props to pass data down to it's children components. Those components in turn pass data down another layer, and so on. Then, to pass data back up the component tree, we use events.

How do I pass Vue components to Props?

Function modeThe URL /search?q=vue would pass {query: 'vue'} as props to the SearchUser component. Try to keep the props function stateless, as it's only evaluated on route changes. Use a wrapper component if you need state to define the props, that way vue can react to state changes.

Are Vue Props required by default?

All props are optional by default, unless required: true is specified. An absent optional prop other than Boolean will have undefined value. The Boolean absent props will be cast to false .


1 Answers

From VueJS docs:

null and undefined values will pass any type validation

Or you can use array and place in it all required types:

propB: [String, Number] 
like image 107
Denys Brustovskyi Avatar answered Sep 28 '22 03:09

Denys Brustovskyi