gpt4 book ai didi

javascript - 如何获得此 react ajax响应并设置状态

转载 作者:行者123 更新时间:2023-12-03 06:01:16 24 4
gpt4 key购买 nike

class Videos extends React.Component{
constructor(){
super();
videoslist:[];
}


_getVideo(skip,limit){

var self= this;
var sess=localStorage.getItem("sessionId");

$.ajax({
method:'GET',
url:'videos',
data:{'sessionId':sess,
'skip':skip,
'limit':limit},
success:function(res){
this.setState({videoslist:res.data})
}.bind(this)
});
}
componentWillMount(){
this._getVideo(0,10);
}

未捕获的类型错误:无法读取 null 的属性“videoslist” 未捕获的类型错误:无法读取 null 的属性“_currentElement”

最佳答案

你的状态初始化有误

constructor(){
super();
this.state = {
videoslist: []
}
}

关于javascript - 如何获得此 react ajax响应并设置状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39742287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com