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.
*
* <strong i="5">@param</strong> {string} url The URL we want to request
* <strong i="6">@param</strong> {object} [options] The options we want to pass to "fetch"
* <strong i="7">@return</strong> {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 }));
}
すみません、2つのリクエストヘッダーを設定することはできませんか?他のブラウザを使用しても問題ありません。また、request.jsのリクエストをajaxまたはAxiosに変更できますか?モデルに影響しますか?
uncaught at anonymous
at takeEvery(auth/login, undefined)
at anonymous
Error: ReferenceError: “Promise”未定义
Promiseポリフィルを追加するだけで、他のajaxライブラリに問題はありません。
@lincenying彼はdva / fetchにカプセル化されていると思いますが、どのように追加しますか?
引き続きフェッチを使用しますか、それとも他のライブラリを使用しますか?
引き続きフェッチを使用する場合は、エントリファイルでポリフィルを引用します。
他のajaxライブラリを使用したい場合は、無視してください...
これが私がaxios
を使う方法です
https://github.com/lincenying/mmf-blog-dva/blob/master/src/utils/request.js
fetchを使用する場合は、npm i promise-polyfill-Sを使用する必要があります
request.jsはこのコードを追加します
'promise-polyfill'からPromiseをインポートします
if(!window.Promise){
window.Promise = Promise;
}