[Base] 更新 SSR 机制, 支持流式渲染注入 head 标签
All checks were successful
Build / build-and-test (push) Successful in 28s

损失的 TTFB 可以忽略不计
This commit is contained in:
2025-06-05 18:02:03 +08:00
parent b1804ae060
commit eca669d62a
9 changed files with 234 additions and 118 deletions

View File

@ -20,9 +20,7 @@ function replaceUrl(url) {
}
export function useApiRequest(method, url, data, config = {}) {
const start = Date.now()
const baseURL = getEndpoint()
// 若为 GET 请求,将 data 转为查询参数拼接到 URL 上
const fullURL = method === 'GET' && data
? `${baseURL}${url}?${objectToQueryString(data)}`
: `${baseURL}${url}`
@ -45,14 +43,14 @@ export function useApiRequest(method, url, data, config = {}) {
}
)
const exec = async () => {
await execute()
const start = Date.now()
try { await execute() }
catch (e) {}
const stop = Date.now()
return {
status: response.value?.status || (error.value?.response?.status ?? -1),
data: response.value?.data || error.value?.response?.data || null,
duration: stop - start,
start,
stop,
error: error.value,
isSSR: import.meta.env.SSR,
}