useFetchRaw.ts 741 B

1234567891011121314151617181920212223242526
  1. import { useFetch as _useFetch } from '#app'
  2. import { webSiteFlagRelation, webSiteLanguageRelation } from "../utils/common";
  3. export async function useFetchRaw<T = any>(url: string, options?: any) {
  4. const config = useRuntimeConfig()
  5. const { appType, serverPath } = config.public as any;
  6. url = url.replace('/api/', serverPath)
  7. const newOptions = {
  8. ...(options ?? {}),
  9. headers: {
  10. ...(options?.headers || {}),
  11. 'Web-Site': webSiteFlagRelation[appType],
  12. Language: webSiteLanguageRelation[appType]
  13. },
  14. }
  15. const { data, error, pending, refresh, execute } = await _useFetch<T>(url, newOptions)
  16. return {
  17. data: {
  18. _rawValue: data.value,
  19. },
  20. error,
  21. pending,
  22. refresh,
  23. execute,
  24. }
  25. }