fetch
the browser's front and rear ends carrying a data processing
cnpm install whatwg-fetch --save
fetch(url,options).then((res)=>res.json()).then((data)=>{})
Features: the first response is not returned, but the structure of a response set of unprocessed
fetch is based on the promise of
axios(url).then(()=>)
fetch(url,options)
Options:
Method: mode request
header: request header
body: the post request when the transmission parameters required place (conversion target to pass into a string) make use of third-party libraries qs
The default is to not carry fetch Cookie If you want to set cookie headers need to set the credentials: include
How to react in cross-domain
Asynchronous action
applyMiddleware: Use action middleware asynchronous processing
The common way to handle asynchronous action
redux-promise-middleware
1。引入
import reduxPromise from "redux-promise-middleware";
2, the use of middleware
const store = createStore(reducer,applyMiddleware(reduxPromise));
3, action processing asynchronous
asynchronous action must be dealt with in the actionCreator
type: "GET_MOVIE",
payload: new new Promise (Resolve => {
// asynchronous
fetchPolyfill ( "? / Ajax / movieOnInfoList = token")
// set untreated result
.then ((res) => res.json () )
.then ((Data) => {
Resolve (Data);
})
})
redux-thunk
redux-saga
dva
In React in what is called middleware?
After the distribution of state action immediately to make changes is called synchronous
action after the payment of state do not know when to change this fact, asynchronous
An application requests and replies between: middleware
React: An application between the action and the reducer