use nuxt plugin instead of function

This commit is contained in:
Jeffrey Hsu 2024-12-18 08:42:26 +08:00
parent 7efa425c85
commit a2736a6385

View File

@ -2,6 +2,7 @@ import type { AsyncData, UseFetchOptions } from '#app'
export function requestCore<DataT>(url: string, options: UseFetchOptions<DataT>) {
// const config = useRuntimeConfig()
const {$mitt} = useNuxtApp()
return useFetch(url, {
baseURL: "https://cantyonion.site",
retry: false,
@ -25,7 +26,7 @@ export function requestCore<DataT>(url: string, options: UseFetchOptions<DataT>)
// }
},
onResponseError({ response }) {
emitter.emit('eventBus', {
$mitt.emit('eventBus', {
level: 'error',
title: `HTTP错误${response.status}`,
message: response.statusText