0
我想獲得從post發回到payload的響應。如何將返回的結果發送到action.How可以這樣做嗎?如何響應發送使用react,redux,axios到動作
import axios from 'axios';
import * as types from './actionTypes';
const ROOT_URL = `http://localhost:8000`;
export function addPost(title){
const url = `${ROOT_URL}/api/v1/post/`;
var request;
axios.post(url, {
title: title,
}).then(function (response) {
request = response;
})
.catch(function (response) {
request = response;
});
console.log(request);
return {
type:types.ADD_POST,
payload:request
}
}
超級有用:http://redux.js.org/docs/advanced/AsyncActions.html – lux