master_basic
linlu 2 years ago
parent 98203fe1b6
commit 634bf12d0d

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

Loading…
Cancel
Save