Use Array/Object in props as default value
See original GitHub issueWhether I can use Array/Object as default value in props setting?
{
props: {
arr: {
type: Array,
default: []
}
}
}
If i may, that will be a bug. Because every instance will share the same thing when I not passing target property to this component. Try this fiddle.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:42
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Vue 2 - How to set default type of array in props - Stack Overflow
I have my Vue component, which is taking an array of objects as a prop. I often use prop validation, especially for 'default'...
Read more >Props | Vue.js
Prop Validation # · All props are optional by default, unless required: true is specified. · An absent optional prop other than Boolean...
Read more >Default value to object prop not working as I expected : r/vuejs
I have this component where I want to have the properties of a given prop to be optional and have a default value....
Read more >Typechecking With PropTypes - React
Default Prop Values ; extends React.Component { ; = { name ; 'stranger' } render ; return ( <div> ; </div> ) } ......
Read more >How to Use Props in Vue.js - freeCodeCamp
“Props” is a special keyword which stands for properties. It can be registered on a component to pass data from a parent component...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can return the default value for a prop inside the
data
function as well:A warning seems necessary in the case you described. A solution would be:
A little verbose, but better with ES6:
If you ended up here looking for how to do it with an object, it looks like this (take note of the brackets):