我以终极版 - 佐贺发送POST请求下面的代码:Fetch Post不能在REDX-SAGA中工作?
import {put, call, fork, takeEvery} from 'redux-saga/effects';
import fetch from 'isomorphic-fetch';
const url = 'xxx/api/posts';
function* addPost(data) {
try{
const response = yield fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json, application/xml, text/plain, text/html, *.*',
'Content-Type': 'application/json; charset=utf-8'
},
body: JSON.stringify(data)
});
const id = yield response.json().id;
yield put({type: types.ADD_POST, payload: {id, title, content }});
}catch(e) {
yield put({type: types.ERROR, payload: e});
}
}
但一个Ajax与“OPTION”方法派,有什么错我的代码?为什么它不起作用?