@data-fair/lib-vue 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fetch.d.ts +1 -0
- package/fetch.js +4 -2
- package/package.json +1 -1
package/fetch.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ type UseFetchOptions = {
|
|
|
4
4
|
query?: QueryObject | Ref<QueryObject>;
|
|
5
5
|
watch?: Boolean;
|
|
6
6
|
notifError?: Boolean;
|
|
7
|
+
immediate?: Boolean;
|
|
7
8
|
};
|
|
8
9
|
type OptionalUrl = string | null | undefined;
|
|
9
10
|
export declare function useFetch<T>(url: OptionalUrl | Ref<OptionalUrl> | (() => OptionalUrl), options?: UseFetchOptions): {
|
package/fetch.js
CHANGED
|
@@ -18,8 +18,8 @@ export function useFetch (url, options = {}) {
|
|
|
18
18
|
const error = shallowRef(null)
|
|
19
19
|
let abortController
|
|
20
20
|
const refresh = async () => {
|
|
21
|
-
if (!fullUrl.value) { return null }
|
|
22
21
|
initialized.value = true
|
|
22
|
+
if (!fullUrl.value) { return null }
|
|
23
23
|
error.value = null
|
|
24
24
|
if (abortController) { abortController.abort() }
|
|
25
25
|
loading.value = true
|
|
@@ -38,7 +38,9 @@ export function useFetch (url, options = {}) {
|
|
|
38
38
|
return data.value
|
|
39
39
|
}
|
|
40
40
|
if (options.watch !== false) {
|
|
41
|
-
watch(fullUrl,
|
|
41
|
+
watch(fullUrl, () => {
|
|
42
|
+
if (options.immediate !== false || initialized.value) { refresh() }
|
|
43
|
+
}, { immediate: true })
|
|
42
44
|
}
|
|
43
45
|
return {
|
|
44
46
|
initialized: readonly(initialized),
|