const headers = { headers:{'Content-Type': 'application/x-www-form-urlencoded'}};
const cookie = {credentials: 'include'};
const baseUrl = 'http://localhost:8088/sjyzx-oauth/';
/**
* Requests a URL, returning a promise.
*
* @param {string} url The URL we want to request
* @param {object} [options] The options we want to pass to "fetch"
* @return {object} An object containing either "data" or "err"
*/
export default function request(url, options) {
return fetch(baseUrl + url, Object.assign({},options, headers, cookie))
.then(checkStatus)
.then(parseJSON)
.then((data) => ({ data }))
.catch((err) => ({ err }));
}
请问一下,是不是我设置了两个请求头就不可以?我用其他浏览器都没问题,或者我能不能把request.js里的请求改成ajax或者Axios,会不会对model有影响?
uncaught at anonymous
at takeEvery(auth/login, undefined)
at anonymous
Error: ReferenceError: “Promise”未定义
加一个Promise的polyfill就行了
用其他ajax库也没任何问题.
@lincenying 我看他那个是封装了dva/fetch里,如何加?
你是想继续用fetch还是用其他库?
如果是想继续用fetch, 在入口文件里引用polyfill,
如果是想用其他的ajax库, 无视就行了...
我是这么用axios
的
https://github.com/lincenying/mmf-blog-dva/blob/master/src/utils/request.js
if you use fetch , you should npm i promise-polyfill -S
request.js add this code
import Promise from 'promise-polyfill'
if (!window.Promise) {
window.Promise = Promise;
}