question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default value for component props

See original GitHub issue

Would be nice to have:

Vue.component("test", {
    "props": [{
        "name": "visible"
        "type": Boolean
        "default": true
    }]
})

Apologies if there are easy ways to implement this (i.e. not by setting manually in the constructor)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

14reactions
yyx990803commented, Jun 26, 2015

Props are just data, so what you return in data will become the default if the parent didn’t provide it:

props: [{
  name: 'visible',
  type: Boolean
}],
data: function () {
  return {
    visible: true
  }
}

Although I agree that having the default directly in props seems better.

0reactions
yyx990803commented, Jun 27, 2015

Closed via 6afe4c5af5517183f636df4d450fbc508a1f5509

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.js: Set a Default value into a prop - Stack Overflow
The defaultProps will be used to ensure that this.props.name will have a value if it was not specified by the parent component.
Read more >
ReactJS defaultProps - GeeksforGeeks
The defaultProps is a React component property that allows you to set default values for the props argument. If the prop property is...
Read more >
React: Everything about Default Props | by Chidume Nnamdi
defaultProps is a property in React component used to set default values for the props argument. It will be changed if the prop...
Read more >
How to specify default value for props in React.js
Well, you can use ES6's object destructuring to specify a default value for the prop. So, previous example can be changed to use...
Read more >
How to set default props in React - Educative.io
Props in React are like function arguments. You can use props to send data to a component. Like default values for function arguments,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found