|
4 | 4 | v-bind="{
|
5 | 5 | content: !!content && patchedIsContent(content) && firstLoad,
|
6 | 6 | errors,
|
7 |
| - loading: loading, |
| 7 | + loading, |
8 | 8 | refresh,
|
9 | 9 | unwrap,
|
10 | 10 | theme,
|
|
38 | 38 | import type { iVuePluginOptions } from "../../types/plugin";
|
39 | 39 | import { useAsyncDataFn } from "../../composables/async";
|
40 | 40 | import { useHelpers } from "../../composables/utils";
|
| 41 | + import useFetchUtils from "../../composables/fetch"; |
41 | 42 |
|
42 | 43 | export interface iLoaderContentFetchProps<Ti, Pi extends any[]> extends iUseThemeProps {
|
43 | 44 | noContentMessage?: string;
|
|
102 | 103 | const emit = defineEmits(["refresh"]);
|
103 | 104 |
|
104 | 105 | const { logger } = useHelpers(useUtils);
|
| 106 | + const { useFetch } = useFetchUtils(); |
105 | 107 | const { internals } = inject<iVuePluginOptions>("xamu") || {};
|
106 | 108 | const useAsyncData: typeof useAsyncDataFn = internals?.useAsyncData ?? useAsyncDataFn;
|
107 | 109 |
|
|
144 | 146 | let newData: T | null = null;
|
145 | 147 |
|
146 | 148 | try {
|
| 149 | + if (props.fallback) firstLoad.value = true; // use fallback while the real content loads |
147 | 150 | if (!props.promise && !props.hydratablePromise && !props.url) return null;
|
148 | 151 | if (props.preventAutoload) {
|
149 | 152 | // is promise like
|
|
152 | 155 | // Prevent on first load or if url is used as key
|
153 | 156 | if (!firstLoad.value || (!!props.url && pl)) return null;
|
154 | 157 | }
|
155 |
| - if (props.fallback) firstLoad.value = true; // use fallback while the real content loads |
156 | 158 | if (props.promise || props.hydratablePromise) {
|
157 | 159 | const payload = <P>(props.payload || []);
|
158 | 160 |
|
|
165 | 167 | )(...payload);
|
166 | 168 | }
|
167 | 169 | } else if (props.url) {
|
168 |
| - const response = await (await fetch(props.url)).json(); |
| 170 | + const response = await useFetch<any>(props.url); |
169 | 171 | const data = "data" in response ? response.data : response;
|
170 | 172 |
|
171 | 173 | if (response.error) throw new Error(response.error);
|
|
202 | 204 | */
|
203 | 205 | const possibleSamePromise = !!newPromise && !!oldPromise;
|
204 | 206 |
|
205 |
| - // prevent muntiple requests |
| 207 | + // prevent multiple requests |
206 | 208 | if (newPromise === oldPromise || !!possibleSamePromise) return;
|
207 | 209 |
|
208 | 210 | // refresh
|
|
0 commit comments