{"id":34794,"date":"2025-05-01T06:02:32","date_gmt":"2025-04-30T22:02:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/34794.html"},"modified":"2025-05-01T06:02:32","modified_gmt":"2025-04-30T22:02:32","slug":"redux-promise-%e4%b8%ad%e9%97%b4%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/34794.html","title":{"rendered":"Redux Promise \u4e2d\u95f4\u4ef6"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250430220231-68129df7ab514.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>&#x1f90d; \u524d\u7aef\u5f00\u53d1\u5de5\u7a0b\u5e08\u3001\u6280\u672f\u65e5\u66f4\u535a\u4e3b\u3001\u5df2\u8fc7CET6 &#x1f368; \u963f\u73ca\u548c\u5979\u7684\u732b_CSDN\u535a\u5ba2\u4e13\u5bb6\u300123\u5e74\u5ea6\u535a\u5ba2\u4e4b\u661f\u524d\u7aef\u9886\u57dfTOP1 &#x1f560; \u725b\u5ba2\u9ad8\u7ea7\u4e13\u9898\u4f5c\u8005\u3001\u6253\u9020\u4e13\u680f\u300a\u524d\u7aef\u9762\u8bd5\u5fc5\u5907\u300b \u3001\u300a2024\u9762\u8bd5\u9ad8\u9891\u624b\u6495\u9898\u300b\u3001\u300a\u524d\u7aef\u6c42\u804c\u7a81\u7834\u8ba1\u5212\u300b &#x1f35a; \u84dd\u6865\u4e91\u8bfe\u7b7e\u7ea6\u4f5c\u8005\u3001\u4e0a\u67b6\u8bfe\u7a0b\u300aVue.js \u548c Egg.js \u5f00\u53d1\u4f01\u4e1a\u7ea7\u5065\u5eb7\u7ba1\u7406\u9879\u76ee\u300b\u3001\u300a\u5e26\u4f60\u4ece\u5165\u95e8\u5230\u5b9e\u6218\u5168\u9762\u638c\u63e1 uni-app\u300b<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li><\/li>\n<li>\n<ul>\n<li>Redux Promise \u4e2d\u95f4\u4ef6\u7684\u4f5c\u7528<\/li>\n<li>\u5b89\u88c5 Redux Promise<\/li>\n<li>\u914d\u7f6e Redux Promise<\/li>\n<li>\u4f7f\u7528 Redux Promise<\/li>\n<li>\n<ul>\n<li>\u5b9a\u4e49 Action Creator<\/li>\n<li>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528<\/li>\n<li>Reducer \u5904\u7406 Promise \u7ed3\u679c<\/li>\n<\/ul>\n<\/li>\n<li>Redux Promise \u7684\u4f18\u52bf<\/li>\n<li>\u7ed3\u8bba<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u5728 Redux \u5e94\u7528\u4e2d&#xff0c;\u5904\u7406\u5f02\u6b65\u64cd\u4f5c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u3002\u9664\u4e86 redux-thunk \u548c redux-saga&#xff0c;redux-promise \u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u5f02\u6b65\u64cd\u4f5c\u7684\u4e2d\u95f4\u4ef6\u3002redux-promise \u5141\u8bb8 dispatch \u65b9\u6cd5\u5206\u53d1\u4e00\u4e2a Promise \u5bf9\u8c61&#xff0c;\u5e76\u5728 Promise \u89e3\u51b3&#xff08;resolve&#xff09;\u6216\u62d2\u7edd&#xff08;reject&#xff09;\u65f6\u5206\u53d1\u76f8\u5e94\u7684 action\u3002<\/p>\n<h3>Redux Promise \u4e2d\u95f4\u4ef6\u7684\u4f5c\u7528<\/h3>\n<p>redux-promise \u4e2d\u95f4\u4ef6\u4f7f\u5f97\u5904\u7406\u57fa\u4e8e Promise \u7684\u5f02\u6b65\u64cd\u4f5c\u53d8\u5f97\u66f4\u52a0\u7b80\u6d01\u3002\u5b83\u5141\u8bb8 action creators \u8fd4\u56de\u4e00\u4e2a Promise \u5bf9\u8c61&#xff0c;\u4e2d\u95f4\u4ef6\u4f1a\u81ea\u52a8\u76d1\u542c\u8fd9\u4e2a Promise \u7684\u72b6\u6001&#xff0c;\u5e76\u6839\u636e\u5176\u89e3\u51b3\u6216\u62d2\u7edd\u7684\u72b6\u6001\u5206\u53d1\u76f8\u5e94\u7684 action\u3002<\/p>\n<h3>\u5b89\u88c5 Redux Promise<\/h3>\n<p>\u9996\u5148&#xff0c;\u9700\u8981\u5b89\u88c5 redux-promise&#xff1a;<\/p>\n<p><span class=\"token function\">npm<\/span> <span class=\"token function\">install<\/span> redux-promise<\/p>\n<h3>\u914d\u7f6e Redux Promise<\/h3>\n<p>\u5728\u521b\u5efa Redux store \u65f6&#xff0c;\u9700\u8981\u5e94\u7528 redux-promise \u4e2d\u95f4\u4ef6&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> createStore<span class=\"token punctuation\">,<\/span> applyMiddleware <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;redux&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> promiseMiddleware <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;redux-promise&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> rootReducer <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;.\/reducers&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> store <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">createStore<\/span><span class=\"token punctuation\">(<\/span>rootReducer<span class=\"token punctuation\">,<\/span> <span class=\"token function\">applyMiddleware<\/span><span class=\"token punctuation\">(<\/span>promiseMiddleware<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> store<span class=\"token punctuation\">;<\/span><\/p>\n<h3>\u4f7f\u7528 Redux Promise<\/h3>\n<h4>\u5b9a\u4e49 Action Creator<\/h4>\n<p>\u4f7f\u7528 redux-promise \u65f6&#xff0c;action creator \u8fd4\u56de\u4e00\u4e2a Promise \u5bf9\u8c61&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ actions.js<\/span><br \/>\n<span class=\"token keyword\">import<\/span> axios <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;axios&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token constant\">FETCH_DATA<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;FETCH_DATA&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">const<\/span> <span class=\"token function-variable function\">fetchData<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> axios<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;https:\/\/api.example.com\/data&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">then<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">response<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> response<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528<\/h4>\n<p>\u5728\u7ec4\u4ef6\u4e2d&#xff0c;\u53ef\u4ee5\u50cf\u5206\u53d1\u666e\u901a action \u4e00\u6837\u5206\u53d1\u8fd4\u56de Promise \u7684 action creator&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> React<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span> useEffect <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;react&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> useDispatch<span class=\"token punctuation\">,<\/span> useSelector <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;react-redux&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> fetchData <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;.\/actions&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token function-variable function\">DataComponent<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> dispatch <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useDispatch<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> data <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useSelector<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">state<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> state<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> loading <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useSelector<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">state<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> state<span class=\"token punctuation\">.<\/span>loading<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> error <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useSelector<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">state<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> state<span class=\"token punctuation\">.<\/span>error<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token function\">useEffect<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">dispatch<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">fetchData<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n      <span class=\"token punctuation\">.<\/span><span class=\"token function\">then<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ Promise resolved<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n      <span class=\"token punctuation\">.<\/span><span class=\"token function\">catch<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ Promise rejected<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span>dispatch<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>loading<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span>Loading<span class=\"token operator\">&#8230;<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>error<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">return<\/span> <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span>Error<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span>error<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>  <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n    <span class=\"token operator\">&lt;<\/span>div<span class=\"token operator\">&gt;<\/span><br \/>\n      <span class=\"token operator\">&lt;<\/span>h1<span class=\"token operator\">&gt;<\/span>Data<span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>h1<span class=\"token operator\">&gt;<\/span><br \/>\n      <span class=\"token operator\">&lt;<\/span>ul<span class=\"token operator\">&gt;<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span>data<span class=\"token punctuation\">.<\/span><span class=\"token function\">map<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token parameter\">item<span class=\"token punctuation\">,<\/span> index<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">(<\/span><br \/>\n          <span class=\"token operator\">&lt;<\/span>li key<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">{<\/span>index<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">{<\/span>item<span class=\"token punctuation\">}<\/span><span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>li<span class=\"token operator\">&gt;<\/span><br \/>\n        <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><br \/>\n      <span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>ul<span class=\"token operator\">&gt;<\/span><br \/>\n    <span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">&gt;<\/span><br \/>\n  <span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> DataComponent<span class=\"token punctuation\">;<\/span><\/p>\n<h4>Reducer \u5904\u7406 Promise \u7ed3\u679c<\/h4>\n<p>Reducer \u9700\u8981\u6839\u636e Promise \u7684\u89e3\u51b3\u6216\u62d2\u7edd\u72b6\u6001\u6765\u66f4\u65b0\u72b6\u6001&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ reducers.js<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token constant\">FETCH_DATA<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token constant\">FETCH_DATA_SUCCESS<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token constant\">FETCH_DATA_FAILURE<\/span> <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;.\/actions&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> initialState <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  data<span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  loading<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span><br \/>\n  error<span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token function-variable function\">rootReducer<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token parameter\">state <span class=\"token operator\">&#061;<\/span> initialState<span class=\"token punctuation\">,<\/span> action<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">switch<\/span> <span class=\"token punctuation\">(<\/span>action<span class=\"token punctuation\">.<\/span>type<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">case<\/span> <span class=\"token constant\">FETCH_DATA<\/span><span class=\"token operator\">:<\/span><br \/>\n      <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token operator\">&#8230;<\/span>state<span class=\"token punctuation\">,<\/span> loading<span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> error<span class=\"token operator\">:<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">case<\/span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token constant\">FETCH_DATA<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\">_PENDING<\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token operator\">:<\/span><br \/>\n      <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token operator\">&#8230;<\/span>state<span class=\"token punctuation\">,<\/span> loading<span class=\"token operator\">:<\/span> <span class=\"token boolean\">true<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">case<\/span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token constant\">FETCH_DATA<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\">_FULFILLED<\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token operator\">:<\/span><br \/>\n      <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token operator\">&#8230;<\/span>state<span class=\"token punctuation\">,<\/span> loading<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span> data<span class=\"token operator\">:<\/span> action<span class=\"token punctuation\">.<\/span>payload <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">case<\/span> <span class=\"token template-string\"><span class=\"token template-punctuation string\">&#096;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${<\/span><span class=\"token constant\">FETCH_DATA<\/span><span class=\"token interpolation-punctuation punctuation\">}<\/span><\/span><span class=\"token string\">_REJECTED<\/span><span class=\"token template-punctuation string\">&#096;<\/span><\/span><span class=\"token operator\">:<\/span><br \/>\n      <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token operator\">&#8230;<\/span>state<span class=\"token punctuation\">,<\/span> loading<span class=\"token operator\">:<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span> error<span class=\"token operator\">:<\/span> action<span class=\"token punctuation\">.<\/span>payload <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">default<\/span><span class=\"token operator\">:<\/span><br \/>\n      <span class=\"token keyword\">return<\/span> state<span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">default<\/span> rootReducer<span class=\"token punctuation\">;<\/span><\/p>\n<h3>Redux Promise \u7684\u4f18\u52bf<\/h3>\n<ul>\n<li>\u7b80\u6d01\u6027&#xff1a;redux-promise \u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u5904\u7406\u57fa\u4e8e Promise \u7684\u5f02\u6b65\u64cd\u4f5c\u3002<\/li>\n<li>\u81ea\u52a8\u5904\u7406&#xff1a;\u4e2d\u95f4\u4ef6\u81ea\u52a8\u76d1\u542c Promise \u7684\u72b6\u6001&#xff0c;\u5e76\u6839\u636e\u5176\u89e3\u51b3\u6216\u62d2\u7edd\u7684\u72b6\u6001\u5206\u53d1\u76f8\u5e94\u7684 action\u3002<\/li>\n<li>\u6613\u4e8e\u96c6\u6210&#xff1a;\u4e0e Redux \u7ed3\u5408\u826f\u597d&#xff0c;\u6613\u4e8e\u96c6\u6210\u5230\u73b0\u6709\u7684 Redux \u5e94\u7528\u4e2d\u3002<\/li>\n<\/ul>\n<h3>\u7ed3\u8bba<\/h3>\n<p>redux-promise \u4e2d\u95f4\u4ef6\u662f\u5904\u7406 Redux \u5e94\u7528\u4e2d\u57fa\u4e8e Promise \u7684\u5f02\u6b65\u64cd\u4f5c\u7684\u4fbf\u6377\u5de5\u5177\u3002\u901a\u8fc7\u4f7f\u7528 redux-promise&#xff0c;\u53ef\u4ee5\u7b80\u5316\u5f02\u6b65\u64cd\u4f5c\u7684\u5904\u7406\u903b\u8f91&#xff0c;\u5e76\u4f7f\u4ee3\u7801\u66f4\u52a0\u6e05\u6670\u548c\u6613\u4e8e\u7ef4\u62a4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4f7f\u7528\u3002<\/p>\n","protected":false},"author":2,"featured_media":34793,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[668,1654],"topic":[],"class_list":["post-34794","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-668","tag-1654"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/34794.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4f7f\u7528\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/34794.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-30T22:02:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250430220231-68129df7ab514.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/34794.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/34794.html\",\"name\":\"Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-30T22:02:32+00:00\",\"dateModified\":\"2025-04-30T22:02:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/34794.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/34794.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/34794.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redux Promise \u4e2d\u95f4\u4ef6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/34794.html","og_locale":"zh_CN","og_type":"article","og_title":"Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e17\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u4f7f\u7528\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/34794.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-30T22:02:32+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250430220231-68129df7ab514.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/34794.html","url":"https:\/\/www.wsisp.com\/helps\/34794.html","name":"Redux Promise \u4e2d\u95f4\u4ef6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-30T22:02:32+00:00","dateModified":"2025-04-30T22:02:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/34794.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/34794.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/34794.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Redux Promise \u4e2d\u95f4\u4ef6"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/34794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=34794"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/34794\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/34793"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=34794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=34794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=34794"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=34794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}