大家好,又见面了,我是你们的朋友全栈君。
import React, { Component } from "react";
export default class Son extends Component {
render() {
return <div>我是子组件---{this.props.text}</div>;
}
}
import React, { Component } from "react";
import Son from "./Son";
export default class Father extends Component {
render() {
return (
<div>
我是父组件
<Son text="父组件的值001" />
</div>
);
}
}
子组件中只能使用不能修改父组件传递过来的数据!!!如果非要修改,那就父组件传递一个方法给子组件,子组件使用这个方法来改变父组件中的数据。这就是react的单项数据流(父组件传递给子组件,不可以在子组件中改变)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/140618.html原文链接:https://javaforall.cn