(1) call
var React = {
createClass:function(spec){ //类组件
spec.render.call(window)
}
};
var CommentBox = React createClass({ //组件类
render:function(){
console.log {this}
)};
(2) var that = this
var oReq = new XMLHttpRequest(); //后台与服务器交换数据
oReq.open ("get", ‘comment2.json‘); //服务器交换接口
oReq.send();
var that = this
oReq.onreaystatechange = function() {
if (oReq.readystate ==4){
var r=eval (oReq.responseText);
//console.log(this)
that.setstate({data});
}else{alert (“服务器错误”+oReq.status)}
}
}bind () //自动调动函数
(3)箭头函数
confirm = (e) => {}
3. constructor //构造函数可以拿到类的this值
4. componentDidMount //页面渲染后调用
5. state //state变化重新渲染 props //控制子元素变化
时间: 2024-10-24 13:19:48