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?
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.
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.
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.
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 .
From VueJS docs:
null
andundefined
values will pass any type validation
Or you can use array and place in it all required types:
propB: [String, Number]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With