得到错误时该方法是使用插座反应时socket.io.on方法被调用然后this.state被undedined
componentDidMount(){
var backapi = api.Backend_API();
var db = this.state.data;
console.log("componentDidMount", this.state.data)
socket.on('notification',
function (notification) {
console.log("avi", notification);
fetch(backapi + "event/eventname/" + notification.event_id, {
method: 'GET',
}).then((response) => response.json())
.then((d) => {
this.setState({
data: d
})
})
fetch(backapi + "user/getUserById/" + notification.created_by, {
method: 'GET'
}).then((response) => response.json())
.then((data) => {
console.log("username socket", data);
})
})
}
称为本地套接字编程获取错误this.setState未定义使用套接字调用此方法时
请帮助我。 – Ranjeet