The interface is no longer called when antd modal is shut down

I use the following methods to monitor incoming data for changes:

 componentWillReceiveProps(nextProps) {
    // 
    if (JSON.stringify(nextProps.data) !== JSON.stringify(this.props.data)) {
      // 
      getSeriesTreeList({ brandid: nextProps.data.brandId }, (data) => {
        let { carListData } = this.state;
        // 
        getModelList({ seriesid: nextProps.data.seriesId }, (modelData) => {
          // 
          for (let i in modelData) {
            modelData[i].value = modelData[i].vmid;
            modelData[i].label = modelData[i].name;
          }
          // 
          for (let i in data) {
            data[i].value = data[i].SeriesID;
            data[i].label = data[i].name;
            data[i].isLeaf = false;
            // 
            if (data[i].SeriesID === nextProps.data.seriesId) {
              data[i].children = modelData
            }
          }
          // 
          for (let i in carListData) {
            if (carListData[i].value === nextProps.data.brandId) {
              carListData[i].children = data;
            }
          }
          let arr = [nextProps.data.brandId, nextProps.data.seriesId, nextProps.data.vmId];
          this.setState({
            carListData,
            carTypeData: arr,
          });
        })
      })
    }
  }

when you click to open modal, if you listen for data changes, you will call the API to query details. However, when you disable modal, no data is passed in. When you call the API, the system will report an error because there is no data to be queried. Is there any way to stop calling the interface when it is shut down?

Mar.14,2021

set a flag to indicate whether the modal is closed or not. Judge before processing the data.


think too much, directly determine whether there is an incoming nextProps.data.brandId , and you can do it with an if without setting other attributes.


you click on the event to open Modal and the event to close Modal is not the same way to handle it. When you close Modal, just set the visibel of Modal to false. Don't deal with anything else

Menu