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 }));
}
معذرةً ، هل من المستحيل أن أضع رأسي طلب؟ ليس لدي مشكلة في استخدام متصفحات أخرى ، أو هل يمكنني تغيير الطلب في request.js إلى ajax أو Axios ، فهل سيؤثر ذلك على النموذج؟
uncaught at anonymous
at takeEvery(auth/login, undefined)
at anonymous
Error: ReferenceError: “Promise”未定义
ما عليك سوى إضافة Promise polyfill ولا توجد مشكلة في مكتبات أجاكس الأخرى.
@ lincenying أعتقد أنه مغلف في dva / fetch ، كيف يمكن إضافته؟
هل تريد الاستمرار في استخدام الجلب أو استخدام مكتبات أخرى؟
إذا كنت تريد الاستمرار في استخدام الجلب ، فاقتبس polyfill في ملف الإدخال ،
إذا كنت تريد استخدام مكتبات أياكس الأخرى ، فتجاهلها فقط ...
هذه هي الطريقة التي أستخدم بها axios
https://github.com/lincenying/mmf-blog-dva/blob/master/src/utils/request.js
إذا كنت تستخدم الجلب ، فيجب عليك npm i وعد-polyfill -S
request.js أضف هذا الرمز
وعد الاستيراد من "وعد بوليفيل"
إذا (! window.Promise) {
window.Promise = وعد ؛
}