一个非常简单的解决方案是在unmount上设置一个标志,并在promise分辨率内使用它,如下所示:
componentDidMount(){ axios.post('mydomian.com/item/',this.state) .then(function (response) { if (this.unmounted) return; const res = response.data if (res.status === 'OK') { this.setState({items :res.list}) }else{ console.log('can not load data', response) } }.bind(this))}componentWillUnmount(){ this.unmounted = true;}


