菜鸡ReactJs-03 组件状态state

2016-06-16  本文已影响10人  菜鸡
<script type="text/jsx">
  var TestState = React.createClass({
    //返回一个默认值
    getInitialState:function(){
      return {
        //是否显示出来
        isVisible: true,
        title: '测试State',
      }
    },
   render:function(){
      return (
        <div>
          //this.state 存储数据
          <h1>{this.state.title}</h1>
        </div>
      )
    }

  });

  var aaa = React.render(
    <TestState />,
    document.getElementById('TestCont'),
    function(){
      console.log('渲染完成。。。');
    }
  )
</script>

1:getInitialState:function( ){ } 这个是设置一个默认值。

2:this.state.xxxxx 这个是存储数据的。

3:因为渲染的时候定义了一个函数aaa,可以直接aaa.setState({xxx:"更新的数据"}) 这样来更新数据。

上一篇 下一篇

猜你喜欢

热点阅读