useFetchRaw.ts 509 B

12345678910111213141516171819202122
  1. import { useFetch as _useFetch } from '#app'
  2. export async function useFetchRaw<T = any>(url: string, options?: any) {
  3. const config = useRuntimeConfig()
  4. const newOptions = {
  5. ...(options ?? {}),
  6. headers: {
  7. ...(options?.headers || {}),
  8. 'X-App-Type': config.public.appType
  9. },
  10. }
  11. const { data, error, pending, refresh, execute } = await _useFetch<T>(url, newOptions)
  12. return {
  13. data: {
  14. _rawValue: data.value,
  15. },
  16. error,
  17. pending,
  18. refresh,
  19. execute,
  20. }
  21. }