Browse Source

isMounted

kulley 7 năm trước cách đây
mục cha
commit
bde3c046bb

+ 11 - 3
src/app/basicVersion/exampleShow/DeployCloudChoose.js

@@ -29,6 +29,7 @@ class DeployCloudChoose extends Component {
     }
 
     componentWillMount() {
+        this._isMounted = true;
         let userID = getCookie('user_id') || this.state.userID;
         if (userID !== undefined && userID !== '') {
             this.setState({
@@ -79,6 +80,10 @@ class DeployCloudChoose extends Component {
         }
     }
 
+    componentWillUnmount() {
+        this._isMounted = false;
+    }
+
     deploy() {
         let _this = this;
         let {userID, dbKind, bucketName} = this.state;
@@ -213,9 +218,12 @@ class DeployCloudChoose extends Component {
                                 console.log(value);
 
                                 // 展示数据
-                                _this.setState({
-                                    disabled: false
-                                });
+                                if(this._isMounted) {
+                                    _this.setState({
+                                        disabled: false
+                                    });
+                                }
+
                                 _this.props.changeTabBar('my-deploy');
                                 _this.props.history.push({
                                     pathname: `/common/deploy`,

+ 10 - 3
src/app/basicVersion/exampleShow/ExampleShow.jsx

@@ -19,18 +19,25 @@ class ExampleShow extends Component {
     }
 
     componentWillMount() {
+        this._isMounted = true;
         request(graphqlUrl, SHOW_CASE, {user_id: 'ioobot'}).then(data => {
             // console.log('eample data',data.case_by_props);
             // Object.prototype.toString.call(data.case_by_props) === '[object Array]';
                 if (Object.prototype.toString.call(data.case_by_props).split(' ')[1].slice(0, -1).toLowerCase() === 'array') {
-                    this.setState({
-                        examples: data.case_by_props
-                    })
+                    if(this._isMounted) {
+                        this.setState({
+                            examples: data.case_by_props
+                        })
+                    }
                 }
             }
         )
     }
 
+    componentWillUnmount() {
+        this._isMounted = false;
+    }
+
 
     render() {
         return (

+ 0 - 1
src/app/basicVersion/myDeploy/AliyunDeploy.js

@@ -26,7 +26,6 @@ class TencentDeploy extends Component {
         let {userID} = this.state;
         if (userID !== 'demo') {
             request(graphqlUrl, SHOW_APIGROUP, {userID}).then(res => {
-                console.log(res);
                 let allDeployed = res.apiGWGroupbyprops;
                 let deployed = allDeployed.filter(deployed =>
                     deployed.cloud_id.cloudName === 'aliyun'

+ 0 - 1
src/app/basicVersion/myDeploy/AmazonDeploy.js

@@ -26,7 +26,6 @@ class TencentDeploy extends Component {
         let {userID} = this.state;
         if (userID !== 'demo') {
             request(graphqlUrl, SHOW_APIGROUP, {userID}).then(res => {
-                console.log(res);
                 let allDeployed = res.apiGWGroupbyprops;
                 let deployed = allDeployed.filter(deployed =>
                     deployed.cloud_id.cloudName === 'amazon'

+ 11 - 5
src/app/basicVersion/myDeploy/TencentDeploy.js

@@ -23,22 +23,28 @@ class TencentDeploy extends Component {
     }
 
     componentWillMount() {
+        this._isMounted = true;
         let {userID} = this.state;
         if (userID !== 'demo') {
             request(graphqlUrl, SHOW_APIGROUP, {userID}).then(res => {
-                console.log(res);
                 let allDeployed = res.apiGWGroupbyprops;
                 let deployed = allDeployed.filter(deployed =>
                     deployed.cloud_id.cloudName === 'tencent'
                 );
-                this.setState({
-                    deployed,
-                    show: true
-                })
+                if(this._isMounted) {
+                    this.setState({
+                        deployed,
+                        show: true
+                    })
+                }
             })
         }
     }
 
+    componentWillUnmount() {
+        this._isMounted = false;
+    }
+
     render() {
         let {userID, url, deployed, show} = this.state;
         return (