{"id":292847,"date":"2021-01-17T22:18:07","date_gmt":"2021-01-17T14:18:07","guid":{"rendered":"http:\/\/4563.org\/?p=292847"},"modified":"2021-01-17T22:18:07","modified_gmt":"2021-01-17T14:18:07","slug":"%e4%b8%80%e4%b8%aa%e5%9b%b0%e6%89%b0%e4%ba%86%e6%88%91-2-%e5%a4%a9%e7%9a%84%e5%89%8d%e7%ab%af%e9%97%ae%e9%a2%98%e5%92%a8%e8%af%a2","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=292847","title":{"rendered":"\u4e00\u4e2a\u56f0\u6270\u4e86\u6211 2 \u5929\u7684\u524d\u7aef\u95ee\u9898\u54a8\u8be2"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4e00\u4e2a\u56f0\u6270\u4e86\u6211 2 \u5929\u7684\u524d\u7aef\u95ee\u9898\u54a8\u8be2               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : rexchen94 <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u8bed\u8a00\uff1aReact<\/p>\n<p>\u4e1a\u52a1\u573a\u666f\uff1a\u6709\u4e00\u5f20\u8868\u683c\uff0c\u8868\u683c\u91cc\u4e00\u884c\u6570\u636e\u4ee3\u8868\u5c06\u8981\u53d1\u8d77\u4e00\u6b21\u8bf7\u6c42\u3002\u6253\u4e2a\u6bd4\u65b9\u6709 10 \u6761\u6570\u636e\uff0c\u73b0\u5728\u8981\u5f02\u6b65\u540c\u65f6\u53d1\u8d77\u8fd9 10 \u4e2a\u8bf7\u6c42\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u5b8c\u6210\u540e\u66f4\u65b0\u8868\u683c\u4e2d\u5bf9\u5e94\u6570\u636e\u7684 loading \u72b6\u6001\uff0csuccess \u72b6\u6001\u548c fail \u72b6\u6001\u3002<\/p>\n<p>\u5f53\u524d\u7684\u5199\u6cd5\uff1a<br \/>\u8868\u683c\u6570\u636e\u662f data\uff0cstack[]\u4e2d\u6709 10 \u4e2a\u8bf7\u6c42\u53c2\u6570\uff0cstack.map(params=&gt;request(params) ; <br \/>request \u51fd\u6570\uff1a (params) =&gt; {<br \/>const temp = [&#8230;data];<br \/>const index = temp.findIndex(row =&gt; row.id === params.id); <br \/>temp.splice(index,1,{&#8230;temp[index],&#8230;{status:&#8217;loading&#8217;}});<br \/>setData(temp); <br \/>axios(params).then( \/\/ \u5229\u7528 splice \u540c\u6837\u5c06 status \u6539\u6210 success \u7136\u540e setData ) }))<\/p>\n<p>\u95ee\u9898\u70b9\uff1a\u8868\u683c\u89c6\u56fe\u4e0a\u72b6\u6001\u4e0d\u80fd\u6210\u529f\u66f4\u65b0\uff0c\u6bcf\u6b21\u72b6\u6001\u66f4\u65b0\u90fd\u4f1a\u8986\u76d6\u4e0a\u4e00\u6b21\u7684\u6570\u636e\uff0c\u5bfc\u81f4\u8868\u683c\u91cc 10 \u6761\u6570\u636e\u6267\u884c\u5230\u54ea\u4e2a\u54ea\u4e2a\u72b6\u6001\u5c31\u662f\u6210\u529f\uff0c\u4f1a\u628a\u5176\u4ed6\u6570\u636e\u7684\u72b6\u6001\u7ed9\u8fd8\u539f\u6210\u7a7a      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5132331\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GDC <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f04\u4e00\u4e2a\u7ec4\u4ef6\u7528\u6765\u5c55\u793a\u6bcf\u884c\u6570\u636e\u7684\u72b6\u6001\uff0c\u6bd4\u5982 Row<br \/>\u628a 10 \u6761\u6570\u636e\u6e32\u67d3\u4e3a 10 \u4e2a Row\uff0c\u6bcf\u4e2a Row \u5904\u7406\u81ea\u8eab\u7684 request \u548c\u66f4\u65b0\u81ea\u5df1\u7684\u72b6\u6001                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132332\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zuiluo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u4e86\u534a\u5929\u624d\u7406\u89e3&#8230;<\/p>\n<p>request \u4e4b\u540e\u8bf7\u91cd\u65b0\u8bfb\u53d6\u4e00\u6b21 current state \u518d\u8fdb\u884c\u64cd\u4f5c\u66f4\u65b0\u5c31\u6ca1\u95ee\u9898\u4e86\uff0c\u800c\u4e0d\u662f\u8bfb\u524d\u9762\u7684 state                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132333\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azcvcza <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u65e2\u7136\u662f\u540c\u65f6\u53d1\u8bf7\u6c42\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u7528<br \/>&#8220;<br \/>Promise.all(array.map(val=&gt;{<br \/> return new Promise(resolve=&gt;{<br \/> return axios.post()<br \/> }).then(res=&gt;{<br \/> resolve(res); <br \/> })<br \/>})).then(resAll=&gt;{<br \/> \/\/ dealWith allResponse<br \/>})<br \/>&#8220;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132334\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : rexchen94 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @azcvcza \u4f60\u8fd9\u6837\u4e0d\u80fd\u5b9e\u65f6\u66f4\u65b0\u8bf7\u6c42\u72b6\u6001\u7684\uff0c\u8981\u7b49\u5168\u90e8\u8bf7\u6c42\u5b8c\u6210\u4e86\u624d\u4f1a\u66f4\u65b0                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132335\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : rexchen94 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @GDC \u597d\u4e3b\u610f\uff0c\u4f46\u662f\u6bcf\u4e2a Row \u5904\u7406\u5b8c\u8fd8\u8981\u53cd\u9988\u7ed9\u7236\u5143\u7d20\u53bb\u505a\u5224\u65ad\u662f\u5426\u5168\u90e8 Row \u90fd\u5b8c\u6210\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132336\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : rexchen94 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @zuiluo \u5f02\u6b65\u6267\u884c\u7684\uff0c\u5982\u679c\u662f\u540c\u6b65\u90a3\u53ef\u4ee5\u8bfb current state                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132337\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zuiluo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @rexchen94 \u4e0d\u7ba1\u5f02\u6b65\u6216\u4e0d\u5f02\u6b65\uff0c\u53d1\u51fa\u591a\u5c11\u8bf7\u6c42\uff0c\u6700\u7ec8\u90fd\u662f\u5355\u7ebf\u7a0b\u5728\u7ebf\u6027\u5904\u7406\uff0c\u6bcf\u6b21\u90fd\u8bfb\u53d6 current state\uff0c\u4e0d\u53ef\u80fd\u51fa\u9519\u3002\u5efa\u8bae review \u4e00\u4e0b\u4ee3\u7801\u662f\u5426\u6709\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132338\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : azcvcza <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90a3\u4f60\u53ef\u80fd\u9700\u8981\u4e00\u4efd\u72ec\u7acb\u7684\u72b6\u6001\u66f4\u65b0\u4e86\uff0cclass component \u4e00\u822c\u662f\u6302\u5728 this.xxx \u4e0a\uff0cfc \u5219\u662f\u7528 useRef \u3002class component \u8fd8\u6709 this.setState(state, callback),\u5728 callback \u91cc\u62ff\u5230\u6700\u65b0\u7684 state\uff0cfc \u91cc\u6ca1\u6709\uff0c\u78b0\u5230\u8fd9\u79cd\u95ee\u9898\uff0c\u597d\u50cf dan abramov \u5efa\u8bae\u662f\u4f18\u5316\u6210\u7528 useReducer \u6765\u66f4\u65b0\u72b6\u6001\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u5b98\u7f51\u4f8b\u5b50\u6216\u8005 dan \u7684 blog\uff0chttps:\/\/overreacted.io\/zh-hans\/a-complete-guide-to-useeffect\/ \u5b50\u6807\u9898\u4e3a\u2018\u89e3\u8026\u6765\u81ea Actions \u7684\u66f4\u65b0\u2019                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132339\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : GDC <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @rexchen94 \u4e3a\u5565\u8fd8\u9700\u8981\u53cd\u9988\u7ed9\u7236\u7ec4\u4ef6\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5132340\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : rexchen94 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @GDC \u56e0\u4e3a\u5f53\u6240\u6709\u8bf7\u6c42\u5168\u90e8\u5b8c\u6210\u65f6\u9700\u8981\u7ed9\u51fa\u63d0\u793a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u56f0\u6270\u4e86\u6211 2 \u5929\u7684\u524d\u7aef\u95ee\u9898\u54a8\u8be2&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/292847"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292847"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/292847\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292847"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}