zoukankan      html  css  js  c++  java
  • fetch的基本应用


    fetch
    浏览器自带的一种前后端数据处理的方式

    cnpm install whatwg-fetch --save


    fetch(url,options).then((res)=>res.json()).then((data)=>{})

    特点:第一次返回的结构不是response 而是一个未处理的response集合

    fetch也是基于promise的


    axios(url).then(()=>)

    fetch(url,options)

    options:
    method:请求的方式
    header:请求头
    body:当post请求的时候需要传递参数的地方(将传递的对象转换成字符串形式的) 利用一下qs 第三方库


    fetch默认是不会携带Cookie的 如果想要设置cookie 需要在headers中设置credentials:include


    react中如何进行跨域

    异步action
    applyMiddleware:使用中间件处理异步的action

    常用处理异步action的方式
    redux-promise-middleware

    1。引入
    import reduxPromise from "redux-promise-middleware";

    2、使用中间件

    const store = createStore(reducer,applyMiddleware(reduxPromise));

    3、处理异步的action
    异步的action必须要在actionCreator中处理

    type:"GET_MOVIE",
    payload:new Promise(resolve=>{
    //异步
    fetchPolyfill("/ajax/movieOnInfoList?token=")
    //未处理的结果集
    .then((res)=>res.json())
    .then((data)=>{
    resolve(data);
    })

    })

    redux-thunk

    redux-saga

    dva

    在React中什么叫做中间件?
    action派发后state立马做出修改 这叫同步
    action派发后state不知道什么时候做修改 这个其实就是异步


    中间件:请求和回复之间的一个应用

    React: action与reducer之间的一个应用

  • 相关阅读:
    iptables
    iftop
    sed&awk
    rz&sz
    关于springboot + mybatis plus 使用事务
    关于JsonArray.toList转换
    jmeter脚本录制
    去掉百度右边的百度热搜等干扰项,集中注意力呀~~
    报错
    图片的异步上传
  • 原文地址:https://www.cnblogs.com/PeiGaGa/p/11032727.html
Copyright © 2011-2022 走看看