react|react - 留言板demo

引入react, 方法一:
import React from 'react'
方法二:
import React,{component} from 'react'
import ReactDom from 'react-dom'
class App extends React.Component{
//存数据的列表
state={list:[]};
//调整this指向
constructor(){
this.update=this.update.bind(this)
};
render(){
return(
//布局渲染






{this.state.list.map((item,index)=>{
return

  • {item.name}/{item.content}

  • })}

    )
    };
    update(){
    this.setState({
    list:this.state.list.concat({
    id:this.state.list.length+1,
    name:this.refs.name.value,
    content:this.refs.content.value
    })
    })
    }
    }
    【react|react - 留言板demo】ReactDom.render(
    ,
    document.querySelect("#root")
    )

      推荐阅读