async getWeibo(pageI=1){
const {contentList,pageIndex,pageSum} = await this.$axios.get("/weibo",{
params:{
pageIndex:pageI
}
})
this.setState({
contentList,
pageIndex,
pageSum
})
}
这个getweibo被props调用后,所有的this都指向props,
但是不想让所有的this都指向props,所以将实例中的this传过去。
另外在传的时候,有写this.getWeibo,此时的this在react解析的时候并没有 解析出来this的指向,所以要bind(this),将实例中的this传过去
class TakeComment extends React.Component{
async addWeibo(){
// console.log(1111111111,this.refs.context.value);
// 提交信息
const data = await this.$axios.post("/weibo",{
content:this.refs.context.value
})
this.refs.context.value = null;
this.props.getWeibo();
}
render(){
return (
<div className="takeComment">
<textarea ref={"context"} name="textarea" className="takeTextField" id="tijiaoText"></textarea>
<div className="takeSbmComment">
<input type="button" onClick={this.addWeibo.bind(this)} className="inputs" value=""/>
</div>
</div>
)
}
}