react(条件渲染例子)

import React, { Component } from 'react';
class IF extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            show: false
        }
    }
    // 渲染函数,this 指向实例本身
    render() {
        let display = this.display.bind(this)//改变this指向
        return


            {/* 这种方法省略了 this 绑定的过程 */}
           
            {this.state.show ?

显示出来啦

: null}
       

    }
    display() {
        this.setState({
            show: !this.state.show
        })
    }
}
export default IF;

你可能感兴趣的:(web大前端)