鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ antd 中 頁面來回切換 ,setState報(bào)錯(cuò)

antd 中 頁面來回切換 ,setState報(bào)錯(cuò)

報(bào)錯(cuò)信息是:
Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

步驟為:
有兩個(gè)頁面,a和b,都是antd的table,在column中render了一個(gè)按鈕

<a key={'btn-delete'}  onClick={() => {
    this.setState({    
        b: Date.now()
    })
}}>刪除</a>

如果現(xiàn)在用this.props.history.push('/b')跳轉(zhuǎn)到b,然后再用this.props.history.push('/a')跳轉(zhuǎn)到a,此時(shí)點(diǎn)擊刪除,就會(huì)報(bào)這個(gè)錯(cuò),但是如果刷新頁面,點(diǎn)擊就不會(huì)報(bào)錯(cuò)

求大神

回答
編輯回答
墨染殤

你的代碼省略掉了關(guān)鍵部分,這個(gè)刪除應(yīng)該有網(wǎng)絡(luò)異步請(qǐng)求。頁面卸載了,執(zhí)行setState當(dāng)然報(bào)錯(cuò)

2018年4月11日 01:50
編輯回答
青裙

提示的很明顯,但你的這段代碼看不出問題。

2017年12月20日 22:47