mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
update
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
/* eslint-disable indent */
|
||||
import { useLocalStorage } from '@vueuse/core'
|
||||
import { APIRoot, PaginationResponse } from './api-models'
|
||||
import { Cookies20Regular } from '@vicons/fluent'
|
||||
|
||||
const cookie = useLocalStorage('JWT_Token', '')
|
||||
|
||||
export async function QueryPostAPI<T>(url: string, body?: unknown, headers?: [string, string][]): Promise<APIRoot<T>> {
|
||||
headers ??= []
|
||||
headers?.push(['Authorization', `Bearer ${cookie.value}`])
|
||||
if (cookie.value) headers?.push(['Authorization', `Bearer ${cookie.value}`])
|
||||
headers?.push(['Content-Type', 'application/json'])
|
||||
|
||||
const data = await fetch(url, {
|
||||
method: 'post',
|
||||
headers: headers,
|
||||
body: JSON.stringify(body),
|
||||
body: typeof body === 'string' ? body : JSON.stringify(body),
|
||||
}) // 不处理异常, 在页面处理
|
||||
return (await data.json()) as APIRoot<T>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user