1하십시오 Child3.js를 만들고 App.js에 도입
Child3 코드 작성
import React, { Component } from 'react'
export default class Child3 extends Component {
constructor(props){
super(props);//用来接收参数
this.state={
num:10
}
console.log("更新属性");
}
add=(n)=>{
this.state.num +=n;
this.forceUpdate();
}
reduce=(n)=>{
this.setState({
num:this.state.num-n
})
}
render() {
console.log("重新渲染页面");
return (
<div>
<button onClick={()=>{
this.add(2);
}}>加法</button>
<span>{this.state.num}</span>
<button onClick={()=>{
this.reduce(3)
}}>减法</button>
</div>
)
}
}
도 코드 코멘트 운전 데이터 페이지 명세서의 세 가지 방법은 다음과 같다 상세