相关疑难解决方法(0)

reactJS如何阻止它听取ajax请求

我在componentdidmount中调用了ajax.然后在ajax promise中使用setState.

代码是这样的

componentDidMount(){
    axios.post('mydomian.com/item/',this.state)
    .then(function (response) {
        const res = response.data
        if (res.status === 'OK') {
            this.setState({items :res.list})
        }else{
            console.log('can not load data', response)
        }
    }.bind(this))
}
componentWillUnmount(){
    how to stop everything about axios?
}
Run Code Online (Sandbox Code Playgroud)

当我导航到其他路线时,这会导致错误'无法在未安装的组件上设置'.

所以我认为我应该做的是删除componentwillunmount中的axios listener.你会怎么做?

reactjs axios

1
推荐指数
1
解决办法
3729
查看次数

标签 统计

axios ×1

reactjs ×1