react 定义组件内默认属性值

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>

)

}

}

实现效果

以上是 react 定义组件内默认属性值 的全部内容, 来源链接: utcz.com/z/381460.html

回到顶部