iT邦幫忙

0

[React] axios - TypeError: Cannot read property 'setState' of undefined

https://stackoverflow.com/questions/41042763/axios-reactjs-cannot-read-property-setstate-of-undefined

將內部的function 改成 es6的 箭頭函數就可以解決

 componentDidMount() {
  axios
  .get(getBaseUrl()+`get`)
  .then((response) => {
    this.setState({name: "RESPONSE TEXT"});
    //this.setState({name: response.data.name});
  })
  .catch((e) => 
  {
    console.error(e);
  });
  //this.setState({});
}

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言