props default value code example

Example 1: default props react

// ES6 class
class CatComponent extends React.Component {    
  constructor(props) {}    
  render() {        
    return <div>{this.props.catName} Cat, 
      Eye Color: {this.props.eyeColor }, 
        Age: {this.props.age}</div>    
  }
}
CatComponent.defaultProps = {    
  catName: "Sandy",    
  eyeColor: "deepblue",    
  age: "120"
}

Example 2: vuejs props

// Component file
<script>
  export default {
    props: {
      name: {
        type: String,
        required: true
      }
    }
  };
</script>

// File you call your component
<template>
  <your-component name="name"></your-component>
</template>

Example 3: vue js default prop

props: {
  name: {
    type: String,
    default: 'John Doe'
  }
}

Tags:

Html Example