useFetchRaw.ts 446 B

12345678910111213141516171819
  1. import { useFetch as _useFetch } from '#app'
  2. import { computed, unref } from 'vue'
  3. export function useFetchRaw<T = any>(url: string, options?: any) {
  4. const { data, error, pending, refresh, execute } = _useFetch<T>(url, options)
  5. // 自动解包 .value,返回一个 computed
  6. const rawData = computed(() => unref(data))
  7. return {
  8. data: {
  9. _rawValue: rawData.value,
  10. },
  11. error,
  12. pending,
  13. refresh,
  14. execute,
  15. }
  16. }