zoukankan      html  css  js  c++  java
  • react中实现异步请求的方法二、redux-promise-middleware

    上篇讲解了redux-thunk中间件的使用,本篇文章介绍一下另一种实现异步请求的的方式,也是使用中间件实现的,但方法略有不同,其他模块一样,只是在actionCreator中请求数据不同,先在store中引入redux-promise-middleware,然后使用中间件。这里只上actionCreator中的代码:

    import {fetch as fetchpro} from "whatwg-fetch";
    //与react-thunk不同的是这里action是一个对象
     export const MovieAction = ()=>({
         type:"GET_MOVIE",
         
         payload:new Promise(resolve=>{
             //异步
             fetchpro("/api/ajax/movieOnInfoList?token=")
             .then(res=>res.json())
             .then((data)=>{
                resolve(data);
             })
         })
     })
    
    
       
  • 相关阅读:
    日报10.29
    日报10.28
    日报10.27
    周进度总结-6
    日报10.25
    日报10.23
    日报10.22
    日报10.21
    日报10.18
    STL bitset
  • 原文地址:https://www.cnblogs.com/PrayLs/p/10505498.html
Copyright © 2011-2022 走看看