react 定义组件内默认属性值


父组件内

import React, { Component } from 'react'; import SYSTEM from './system' export default class Login extends Component{ constructor(props){ super(props) this.state={ } } render(){ return ( <div>
                <SYSTEM name="第一"></SYSTEM>
                <SYSTEM name="第二"></SYSTEM>
                <SYSTEM></SYSTEM>
                <SYSTEM name="第四"></SYSTEM>
            </div> ) } }

子组件内

import React,{Component} from 'react' export default class system extends Component{ constructor(props){ super(props) this.state = {} } static defaultProps = { name:'点击我' } render(){ return ( <div>
                <button>{this.props.name}</button>
            </div> ) } } 

实现效果

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM