데이터 디스플레이 정적 데이터 11React 단방향 동작

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>
        )
    }
}

도 코드 코멘트 운전 데이터 페이지 명세서의 세 가지 방법은 다음과 같다 상세

 

게시 13 개 원래 기사 · 원의 찬양 (28) · 전망 1362

추천

출처blog.csdn.net/ldc121xy716/article/details/103989117