fetchJson.js 807 Bytes
Newer Older
1 2
import { getToken } from '@/utils/authority';
import { getHeaders } from '@/webPublic/zyd_public/utils/getHeaders';
3
import { getIsBei_Dian } from '@/webPublic/zyd_public/utils/getSchoolType';
4 5 6

const token = getToken();
export default function fetchJSON(url, body) {
7
	if (url.indexOf('token=') <= -1 && !getIsBei_Dian()) {
8 9 10 11 12
		url = url + '?token=' + token;
	}
	return fetch(url, {
		method: 'post',
		body: JSON.stringify(body),
13
    credentials: 'include', // 确保浏览器不在请求中包含凭据 // 用这个本地访问北电科会跨域
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    mode: 'cors',
		headers: {
			'Content-Type': 'application/json',
			Accept: 'application/json',
			...getHeaders(url).headers,
		},
	})
		.then(function(res) {
			return res.json();
		})
		.then(function(data) {
			console.log(data);
			return data;
		});
}