亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

TypeError:無法讀取未定義的屬性“groupsUrl”

TypeError:無法讀取未定義的屬性“groupsUrl”

慕雪6442864 2022-10-08 10:11:25
試圖讓我的狀態每 5 秒從我的 db api 更新一次,但我收到一個錯誤,即即使它是狀態也沒有定義。我知道 setState 是異步的,但是在 componentDidMount 中它可以讀取狀態,因此按照我的邏輯,如果 componentDidMount 調用 reSetStates 它肯定能夠讀取狀態。class Groups extends Component {  state = {    groups : {},    categories : ["id", "name", "last fault", "active"],    groupsInfoList : [],    enabledGroupsInfoList : [],    disabledGroupsInfoList : [],    groupsUrl : 'http://my.api.server/groups'  }  componentDidMount() {    fetch(this.state.groupsUrl)    .then(res => res.json())    .then((data) => {      var groups_object = data['result']      this.setStates(groups_object)      this.reSetStates()    })    .catch(console.log)  }  reSetStates(){    fetch(this.state.groupsUrl)    .then(res => res.json())    .then((data) => {      var groups_object = data['result']      this.setStates(groups_object)    })    .catch(console.log)    setTimeout(this.reSetStates, 3000);  }
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

這是綁定問題,改變這個

reSetStates(){

至:

reSetStates = () => {


查看完整回答
反對 回復 2022-10-08
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號