// import 'es5-shim' //由于 IE8 是 ES3,需要引入 ES5 的 polyfill
// require('es6-promise').polyfill(); //支持IE浏览器,引入 Promise 的 polyfill
// import 'whatwg-fetch' //解决移动浏览器兼容性问题
// import 'fetch-detector' //引入 fetch 探测库
// import 'fetch-ie8' //引入 fetch 的 polyfill
let baseUrl = ''
export default async(url = '', data = {}, type = 'GET', contentType = 'application/json', method = 'fetch') => {
type = type.toUpperCase();
url = baseUrl + url;
contentType = contentType.toLowerCase();
if (type === 'GET') {
let dataStr = '';
Object.keys(data).forEach(key => {
dataStr += key + '=' + data[key] + '&'
})
dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'))
url &#
自定义封装fetch
最新推荐文章于 2024-05-10 09:53:18 发布