ReactJs 技巧

1、fn.bind(this)  

 success:function(res){

  this.setState()

}.bind(this)

当在回调函数内调用组件的this方法时可以在函数后上.bind(this)这样内部就可以用this了

2、<View1 url="XX.json" />

组件引用时调用json

3、render 返回模板return ()

用()来包起标签

4、render返回模板标签需要在容器内如div内

5、render 返回模板内可以输出js 变量或函数的{vhtml}

函数需要返回标签的。

6、render内可以嵌套组件

7、数组遍历

this.props.Xx.map(fn(item){

   return ()

});

8、this.refs.Xx.getDOMNode() 获取原生的标签

9、组件内定义的方法可以绑定在嵌套组件属性上,嵌套内用this.props.XX来访问父级方法。实现方法传递。

10、修改状态对象内的数组

先保存到一个变量内,添加用concat() 删除用a.splice(index,1)  最后用setState来修改

11、销毁组件

React.unmountComponentAtNode(组件生成的标签)

会触发组件的componentWillUnmount方法

可以用来删除记时器等




你可能感兴趣的:(ReactJs 技巧)