react父传子(以及默认值)
作者:互联网
子组件
import React, { Component } from "react";
import "./base.css"
// 父组件
export class TestHanderClick extends Component {
// static defaultProps是默认的写法,人家规定这样写的,你的默认值
static defaultProps={
bg:"pink",
wi:"100px",
he:"100px"
}
render() {
return (
// 使用值
<div style={{ background: this.props.bg, width: this.props.wi, height:this.props.he }}>
123
</div>
)
}
}
export default TestHanderClick;
父组件
{/* 父组件传递给子组件的值 */}
<TestHanderClick bg="blue"></TestHanderClick>
标签:Component,100px,react,static,父传子,组件,import,默认值 来源: https://www.cnblogs.com/ishoulgodo/p/13526534.html