|
|
|
@ -20,6 +20,7 @@ export function getRequest(url: string, params: object) {
|
|
|
|
|
|
|
|
|
|
return fetch(urlWithParams, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
@ -47,6 +48,7 @@ export function postRequest(url: string, data: object) {
|
|
|
|
|
'User-Agent': '',
|
|
|
|
|
'sec-ch-ua': ''
|
|
|
|
|
},
|
|
|
|
|
mode:"cors",
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -71,6 +73,7 @@ export function postFormDataRequest(url: string, data: object) {
|
|
|
|
|
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
body: formData
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -90,6 +93,7 @@ export function deleteRequest(url: string, params: object) {
|
|
|
|
|
const searchParams = new URLSearchParams(params);
|
|
|
|
|
return fetch(`${url}?${searchParams.toString()}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) { throw new Error('请求失败'); }
|
|
|
|
@ -111,6 +115,7 @@ export function putRequest(url: string, data: object) {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
mode:"cors",
|
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -130,6 +135,7 @@ export function putRequest(url: string, data: object) {
|
|
|
|
|
export function downloadFile(url: string, fileName?: string) {
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) { throw new Error('下载失败'); }
|
|
|
|
|