@vueuse/skills 14.2.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/LICENSE +21 -0
- package/README.md +643 -0
- package/package.json +36 -0
- package/skills/vueuse-functions/SKILL.md +417 -0
- package/skills/vueuse-functions/references/computedAsync.md +195 -0
- package/skills/vueuse-functions/references/computedEager.md +62 -0
- package/skills/vueuse-functions/references/computedInject.md +137 -0
- package/skills/vueuse-functions/references/computedWithControl.md +98 -0
- package/skills/vueuse-functions/references/createEventHook.md +86 -0
- package/skills/vueuse-functions/references/createGenericProjection.md +25 -0
- package/skills/vueuse-functions/references/createGlobalState.md +95 -0
- package/skills/vueuse-functions/references/createInjectionState.md +215 -0
- package/skills/vueuse-functions/references/createProjection.md +31 -0
- package/skills/vueuse-functions/references/createRef.md +54 -0
- package/skills/vueuse-functions/references/createReusableTemplate.md +356 -0
- package/skills/vueuse-functions/references/createSharedComposable.md +42 -0
- package/skills/vueuse-functions/references/createTemplatePromise.md +306 -0
- package/skills/vueuse-functions/references/createUnrefFn.md +51 -0
- package/skills/vueuse-functions/references/extendRef.md +76 -0
- package/skills/vueuse-functions/references/from.md +80 -0
- package/skills/vueuse-functions/references/get.md +30 -0
- package/skills/vueuse-functions/references/injectLocal.md +35 -0
- package/skills/vueuse-functions/references/isDefined.md +31 -0
- package/skills/vueuse-functions/references/logicAnd.md +40 -0
- package/skills/vueuse-functions/references/logicNot.md +36 -0
- package/skills/vueuse-functions/references/logicOr.md +40 -0
- package/skills/vueuse-functions/references/makeDestructurable.md +41 -0
- package/skills/vueuse-functions/references/onClickOutside.md +221 -0
- package/skills/vueuse-functions/references/onElementRemoval.md +88 -0
- package/skills/vueuse-functions/references/onKeyStroke.md +211 -0
- package/skills/vueuse-functions/references/onLongPress.md +227 -0
- package/skills/vueuse-functions/references/onStartTyping.md +53 -0
- package/skills/vueuse-functions/references/provideLocal.md +37 -0
- package/skills/vueuse-functions/references/reactify.md +144 -0
- package/skills/vueuse-functions/references/reactifyObject.md +62 -0
- package/skills/vueuse-functions/references/reactiveComputed.md +34 -0
- package/skills/vueuse-functions/references/reactiveOmit.md +86 -0
- package/skills/vueuse-functions/references/reactivePick.md +106 -0
- package/skills/vueuse-functions/references/refAutoReset.md +46 -0
- package/skills/vueuse-functions/references/refDebounced.md +81 -0
- package/skills/vueuse-functions/references/refDefault.md +36 -0
- package/skills/vueuse-functions/references/refManualReset.md +44 -0
- package/skills/vueuse-functions/references/refThrottled.md +99 -0
- package/skills/vueuse-functions/references/refWithControl.md +146 -0
- package/skills/vueuse-functions/references/set.md +30 -0
- package/skills/vueuse-functions/references/syncRef.md +195 -0
- package/skills/vueuse-functions/references/syncRefs.md +128 -0
- package/skills/vueuse-functions/references/templateRef.md +86 -0
- package/skills/vueuse-functions/references/toObserver.md +38 -0
- package/skills/vueuse-functions/references/toReactive.md +41 -0
- package/skills/vueuse-functions/references/toRef.md +75 -0
- package/skills/vueuse-functions/references/toRefs.md +81 -0
- package/skills/vueuse-functions/references/tryOnBeforeMount.md +34 -0
- package/skills/vueuse-functions/references/tryOnBeforeUnmount.md +32 -0
- package/skills/vueuse-functions/references/tryOnMounted.md +34 -0
- package/skills/vueuse-functions/references/tryOnScopeDispose.md +31 -0
- package/skills/vueuse-functions/references/tryOnUnmounted.md +32 -0
- package/skills/vueuse-functions/references/unrefElement.md +54 -0
- package/skills/vueuse-functions/references/until.md +161 -0
- package/skills/vueuse-functions/references/useAbs.md +31 -0
- package/skills/vueuse-functions/references/useActiveElement.md +85 -0
- package/skills/vueuse-functions/references/useAnimate.md +181 -0
- package/skills/vueuse-functions/references/useArrayDifference.md +84 -0
- package/skills/vueuse-functions/references/useArrayEvery.md +59 -0
- package/skills/vueuse-functions/references/useArrayFilter.md +63 -0
- package/skills/vueuse-functions/references/useArrayFind.md +50 -0
- package/skills/vueuse-functions/references/useArrayFindIndex.md +59 -0
- package/skills/vueuse-functions/references/useArrayFindLast.md +52 -0
- package/skills/vueuse-functions/references/useArrayIncludes.md +63 -0
- package/skills/vueuse-functions/references/useArrayJoin.md +74 -0
- package/skills/vueuse-functions/references/useArrayMap.md +59 -0
- package/skills/vueuse-functions/references/useArrayReduce.md +81 -0
- package/skills/vueuse-functions/references/useArraySome.md +59 -0
- package/skills/vueuse-functions/references/useArrayUnique.md +76 -0
- package/skills/vueuse-functions/references/useAsyncQueue.md +136 -0
- package/skills/vueuse-functions/references/useAsyncState.md +185 -0
- package/skills/vueuse-functions/references/useAsyncValidator.md +70 -0
- package/skills/vueuse-functions/references/useAuth.md +123 -0
- package/skills/vueuse-functions/references/useAverage.md +36 -0
- package/skills/vueuse-functions/references/useAxios.md +322 -0
- package/skills/vueuse-functions/references/useBase64.md +136 -0
- package/skills/vueuse-functions/references/useBattery.md +78 -0
- package/skills/vueuse-functions/references/useBluetooth.md +175 -0
- package/skills/vueuse-functions/references/useBreakpoints.md +172 -0
- package/skills/vueuse-functions/references/useBroadcastChannel.md +74 -0
- package/skills/vueuse-functions/references/useBrowserLocation.md +83 -0
- package/skills/vueuse-functions/references/useCached.md +52 -0
- package/skills/vueuse-functions/references/useCeil.md +31 -0
- package/skills/vueuse-functions/references/useChangeCase.md +79 -0
- package/skills/vueuse-functions/references/useClamp.md +85 -0
- package/skills/vueuse-functions/references/useClipboard.md +123 -0
- package/skills/vueuse-functions/references/useClipboardItems.md +94 -0
- package/skills/vueuse-functions/references/useCloned.md +91 -0
- package/skills/vueuse-functions/references/useColorMode.md +172 -0
- package/skills/vueuse-functions/references/useConfirmDialog.md +159 -0
- package/skills/vueuse-functions/references/useCookies.md +162 -0
- package/skills/vueuse-functions/references/useCountdown.md +105 -0
- package/skills/vueuse-functions/references/useCounter.md +86 -0
- package/skills/vueuse-functions/references/useCssSupports.md +35 -0
- package/skills/vueuse-functions/references/useCssVar.md +50 -0
- package/skills/vueuse-functions/references/useCurrentElement.md +61 -0
- package/skills/vueuse-functions/references/useCycleList.md +75 -0
- package/skills/vueuse-functions/references/useDark.md +144 -0
- package/skills/vueuse-functions/references/useDateFormat.md +145 -0
- package/skills/vueuse-functions/references/useDebounceFn.md +100 -0
- package/skills/vueuse-functions/references/useDebouncedRefHistory.md +40 -0
- package/skills/vueuse-functions/references/useDeviceMotion.md +86 -0
- package/skills/vueuse-functions/references/useDeviceOrientation.md +62 -0
- package/skills/vueuse-functions/references/useDevicePixelRatio.md +44 -0
- package/skills/vueuse-functions/references/useDevicesList.md +90 -0
- package/skills/vueuse-functions/references/useDisplayMedia.md +71 -0
- package/skills/vueuse-functions/references/useDocumentVisibility.md +45 -0
- package/skills/vueuse-functions/references/useDraggable.md +317 -0
- package/skills/vueuse-functions/references/useDrauu.md +65 -0
- package/skills/vueuse-functions/references/useDropZone.md +83 -0
- package/skills/vueuse-functions/references/useElementBounding.md +131 -0
- package/skills/vueuse-functions/references/useElementByPoint.md +48 -0
- package/skills/vueuse-functions/references/useElementHover.md +79 -0
- package/skills/vueuse-functions/references/useElementSize.md +78 -0
- package/skills/vueuse-functions/references/useElementVisibility.md +123 -0
- package/skills/vueuse-functions/references/useEventBus.md +101 -0
- package/skills/vueuse-functions/references/useEventListener.md +226 -0
- package/skills/vueuse-functions/references/useEventSource.md +204 -0
- package/skills/vueuse-functions/references/useExtractedObservable.md +198 -0
- package/skills/vueuse-functions/references/useEyeDropper.md +71 -0
- package/skills/vueuse-functions/references/useFavicon.md +67 -0
- package/skills/vueuse-functions/references/useFetch.md +546 -0
- package/skills/vueuse-functions/references/useFileDialog.md +91 -0
- package/skills/vueuse-functions/references/useFileSystemAccess.md +162 -0
- package/skills/vueuse-functions/references/useFirestore.md +129 -0
- package/skills/vueuse-functions/references/useFloor.md +31 -0
- package/skills/vueuse-functions/references/useFocus.md +99 -0
- package/skills/vueuse-functions/references/useFocusTrap.md +245 -0
- package/skills/vueuse-functions/references/useFocusWithin.md +57 -0
- package/skills/vueuse-functions/references/useFps.md +28 -0
- package/skills/vueuse-functions/references/useFullscreen.md +75 -0
- package/skills/vueuse-functions/references/useFuse.md +107 -0
- package/skills/vueuse-functions/references/useGamepad.md +222 -0
- package/skills/vueuse-functions/references/useGeolocation.md +85 -0
- package/skills/vueuse-functions/references/useIDBKeyval.md +93 -0
- package/skills/vueuse-functions/references/useIdle.md +88 -0
- package/skills/vueuse-functions/references/useImage.md +86 -0
- package/skills/vueuse-functions/references/useInfiniteScroll.md +157 -0
- package/skills/vueuse-functions/references/useIntersectionObserver.md +118 -0
- package/skills/vueuse-functions/references/useInterval.md +112 -0
- package/skills/vueuse-functions/references/useIntervalFn.md +50 -0
- package/skills/vueuse-functions/references/useIpcRenderer.md +144 -0
- package/skills/vueuse-functions/references/useIpcRendererInvoke.md +58 -0
- package/skills/vueuse-functions/references/useIpcRendererOn.md +52 -0
- package/skills/vueuse-functions/references/useJwt.md +57 -0
- package/skills/vueuse-functions/references/useKeyModifier.md +87 -0
- package/skills/vueuse-functions/references/useLastChanged.md +63 -0
- package/skills/vueuse-functions/references/useLocalStorage.md +41 -0
- package/skills/vueuse-functions/references/useMagicKeys.md +245 -0
- package/skills/vueuse-functions/references/useManualRefHistory.md +204 -0
- package/skills/vueuse-functions/references/useMath.md +47 -0
- package/skills/vueuse-functions/references/useMax.md +36 -0
- package/skills/vueuse-functions/references/useMediaControls.md +571 -0
- package/skills/vueuse-functions/references/useMediaQuery.md +53 -0
- package/skills/vueuse-functions/references/useMemoize.md +175 -0
- package/skills/vueuse-functions/references/useMemory.md +71 -0
- package/skills/vueuse-functions/references/useMin.md +36 -0
- package/skills/vueuse-functions/references/useMounted.md +38 -0
- package/skills/vueuse-functions/references/useMouse.md +113 -0
- package/skills/vueuse-functions/references/useMouseInElement.md +123 -0
- package/skills/vueuse-functions/references/useMousePressed.md +112 -0
- package/skills/vueuse-functions/references/useMutationObserver.md +61 -0
- package/skills/vueuse-functions/references/useNProgress.md +78 -0
- package/skills/vueuse-functions/references/useNavigatorLanguage.md +57 -0
- package/skills/vueuse-functions/references/useNetwork.md +106 -0
- package/skills/vueuse-functions/references/useNow.md +79 -0
- package/skills/vueuse-functions/references/useObjectUrl.md +55 -0
- package/skills/vueuse-functions/references/useObservable.md +91 -0
- package/skills/vueuse-functions/references/useOffsetPagination.md +199 -0
- package/skills/vueuse-functions/references/useOnline.md +41 -0
- package/skills/vueuse-functions/references/usePageLeave.md +42 -0
- package/skills/vueuse-functions/references/useParallax.md +58 -0
- package/skills/vueuse-functions/references/useParentElement.md +54 -0
- package/skills/vueuse-functions/references/usePerformanceObserver.md +48 -0
- package/skills/vueuse-functions/references/usePermission.md +79 -0
- package/skills/vueuse-functions/references/usePointer.md +89 -0
- package/skills/vueuse-functions/references/usePointerLock.md +60 -0
- package/skills/vueuse-functions/references/usePointerSwipe.md +80 -0
- package/skills/vueuse-functions/references/usePrecision.md +49 -0
- package/skills/vueuse-functions/references/usePreferredColorScheme.md +42 -0
- package/skills/vueuse-functions/references/usePreferredContrast.md +42 -0
- package/skills/vueuse-functions/references/usePreferredDark.md +41 -0
- package/skills/vueuse-functions/references/usePreferredLanguages.md +41 -0
- package/skills/vueuse-functions/references/usePreferredReducedMotion.md +42 -0
- package/skills/vueuse-functions/references/usePreferredReducedTransparency.md +42 -0
- package/skills/vueuse-functions/references/usePrevious.md +40 -0
- package/skills/vueuse-functions/references/useProjection.md +38 -0
- package/skills/vueuse-functions/references/useQRCode.md +53 -0
- package/skills/vueuse-functions/references/useRTDB.md +83 -0
- package/skills/vueuse-functions/references/useRafFn.md +68 -0
- package/skills/vueuse-functions/references/useRefHistory.md +285 -0
- package/skills/vueuse-functions/references/useResizeObserver.md +109 -0
- package/skills/vueuse-functions/references/useRound.md +31 -0
- package/skills/vueuse-functions/references/useRouteHash.md +27 -0
- package/skills/vueuse-functions/references/useRouteParams.md +38 -0
- package/skills/vueuse-functions/references/useRouteQuery.md +79 -0
- package/skills/vueuse-functions/references/useSSRWidth.md +47 -0
- package/skills/vueuse-functions/references/useScreenOrientation.md +96 -0
- package/skills/vueuse-functions/references/useScreenSafeArea.md +60 -0
- package/skills/vueuse-functions/references/useScriptTag.md +116 -0
- package/skills/vueuse-functions/references/useScroll.md +238 -0
- package/skills/vueuse-functions/references/useScrollLock.md +66 -0
- package/skills/vueuse-functions/references/useSessionStorage.md +41 -0
- package/skills/vueuse-functions/references/useShare.md +68 -0
- package/skills/vueuse-functions/references/useSortable.md +235 -0
- package/skills/vueuse-functions/references/useSorted.md +90 -0
- package/skills/vueuse-functions/references/useSpeechRecognition.md +94 -0
- package/skills/vueuse-functions/references/useSpeechSynthesis.md +105 -0
- package/skills/vueuse-functions/references/useStepper.md +137 -0
- package/skills/vueuse-functions/references/useStorage.md +278 -0
- package/skills/vueuse-functions/references/useStorageAsync.md +136 -0
- package/skills/vueuse-functions/references/useStyleTag.md +131 -0
- package/skills/vueuse-functions/references/useSubject.md +77 -0
- package/skills/vueuse-functions/references/useSubscription.md +33 -0
- package/skills/vueuse-functions/references/useSum.md +36 -0
- package/skills/vueuse-functions/references/useSupported.md +29 -0
- package/skills/vueuse-functions/references/useSwipe.md +75 -0
- package/skills/vueuse-functions/references/useTemplateRefsList.md +37 -0
- package/skills/vueuse-functions/references/useTextDirection.md +75 -0
- package/skills/vueuse-functions/references/useTextSelection.md +40 -0
- package/skills/vueuse-functions/references/useTextareaAutosize.md +97 -0
- package/skills/vueuse-functions/references/useThrottleFn.md +57 -0
- package/skills/vueuse-functions/references/useThrottledRefHistory.md +47 -0
- package/skills/vueuse-functions/references/useTimeAgo.md +154 -0
- package/skills/vueuse-functions/references/useTimeAgoIntl.md +117 -0
- package/skills/vueuse-functions/references/useTimeout.md +113 -0
- package/skills/vueuse-functions/references/useTimeoutFn.md +51 -0
- package/skills/vueuse-functions/references/useTimeoutPoll.md +47 -0
- package/skills/vueuse-functions/references/useTimestamp.md +89 -0
- package/skills/vueuse-functions/references/useTitle.md +113 -0
- package/skills/vueuse-functions/references/useToNumber.md +54 -0
- package/skills/vueuse-functions/references/useToString.md +34 -0
- package/skills/vueuse-functions/references/useToggle.md +103 -0
- package/skills/vueuse-functions/references/useTransition.md +265 -0
- package/skills/vueuse-functions/references/useTrunc.md +33 -0
- package/skills/vueuse-functions/references/useUrlSearchParams.md +121 -0
- package/skills/vueuse-functions/references/useUserMedia.md +1138 -0
- package/skills/vueuse-functions/references/useVModel.md +182 -0
- package/skills/vueuse-functions/references/useVModels.md +67 -0
- package/skills/vueuse-functions/references/useVibrate.md +87 -0
- package/skills/vueuse-functions/references/useVirtualList.md +182 -0
- package/skills/vueuse-functions/references/useWakeLock.md +50 -0
- package/skills/vueuse-functions/references/useWebNotification.md +176 -0
- package/skills/vueuse-functions/references/useWebSocket.md +299 -0
- package/skills/vueuse-functions/references/useWebWorker.md +60 -0
- package/skills/vueuse-functions/references/useWebWorkerFn.md +102 -0
- package/skills/vueuse-functions/references/useWindowFocus.md +46 -0
- package/skills/vueuse-functions/references/useWindowScroll.md +61 -0
- package/skills/vueuse-functions/references/useWindowSize.md +76 -0
- package/skills/vueuse-functions/references/useZoomFactor.md +53 -0
- package/skills/vueuse-functions/references/useZoomLevel.md +53 -0
- package/skills/vueuse-functions/references/watchArray.md +53 -0
- package/skills/vueuse-functions/references/watchAtMost.md +55 -0
- package/skills/vueuse-functions/references/watchDebounced.md +101 -0
- package/skills/vueuse-functions/references/watchDeep.md +54 -0
- package/skills/vueuse-functions/references/watchExtractedObservable.md +192 -0
- package/skills/vueuse-functions/references/watchIgnorable.md +120 -0
- package/skills/vueuse-functions/references/watchImmediate.md +44 -0
- package/skills/vueuse-functions/references/watchOnce.md +41 -0
- package/skills/vueuse-functions/references/watchPausable.md +86 -0
- package/skills/vueuse-functions/references/watchThrottled.md +108 -0
- package/skills/vueuse-functions/references/watchTriggerable.md +98 -0
- package/skills/vueuse-functions/references/watchWithFilter.md +54 -0
- package/skills/vueuse-functions/references/whenever.md +100 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Utilities
|
|
3
|
+
related: useThrottleFn
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# useDebounceFn
|
|
7
|
+
|
|
8
|
+
Debounce execution of a function.
|
|
9
|
+
|
|
10
|
+
> Debounce is an overloaded waiter: if you keep asking, your requests will be ignored until you stop and give them some time to think about your latest inquiry.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { useDebounceFn, useEventListener } from '@vueuse/core'
|
|
16
|
+
|
|
17
|
+
const debouncedFn = useDebounceFn(() => {
|
|
18
|
+
// do something
|
|
19
|
+
}, 1000)
|
|
20
|
+
|
|
21
|
+
useEventListener(window, 'resize', debouncedFn)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You can also pass a 3rd parameter to this, with a maximum wait time, similar to [lodash debounce](https://lodash.com/docs/4.17.15#debounce)
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { useDebounceFn, useEventListener } from '@vueuse/core'
|
|
28
|
+
|
|
29
|
+
// If no invokation after 5000ms due to repeated input,
|
|
30
|
+
// the function will be called anyway.
|
|
31
|
+
const debouncedFn = useDebounceFn(() => {
|
|
32
|
+
// do something
|
|
33
|
+
}, 1000, { maxWait: 5000 })
|
|
34
|
+
|
|
35
|
+
useEventListener(window, 'resize', debouncedFn)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Optionally, you can get the return value of the function using promise operations.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { useDebounceFn } from '@vueuse/core'
|
|
42
|
+
|
|
43
|
+
const debouncedRequest = useDebounceFn(() => 'response', 1000)
|
|
44
|
+
|
|
45
|
+
debouncedRequest().then((value) => {
|
|
46
|
+
console.log(value) // 'response'
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// or use async/await
|
|
50
|
+
async function doRequest() {
|
|
51
|
+
const value = await debouncedRequest()
|
|
52
|
+
console.log(value) // 'response'
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Since unhandled rejection error is quite annoying when developer doesn't need the return value, the promise will **NOT** be rejected if the function is canceled **by default**. You need to specify the option `rejectOnCancel: true` to capture the rejection.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { useDebounceFn } from '@vueuse/core'
|
|
60
|
+
|
|
61
|
+
const debouncedRequest = useDebounceFn(() => 'response', 1000, { rejectOnCancel: true })
|
|
62
|
+
|
|
63
|
+
debouncedRequest()
|
|
64
|
+
.then((value) => {
|
|
65
|
+
// do something
|
|
66
|
+
})
|
|
67
|
+
.catch(() => {
|
|
68
|
+
// do something when canceled
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
// calling it again will cancel the previous request and gets rejected
|
|
72
|
+
setTimeout(debouncedRequest, 500)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Recommended Reading
|
|
76
|
+
|
|
77
|
+
- [**Debounce vs Throttle**: Definitive Visual Guide](https://kettanaito.com/blog/debounce-vs-throttle)
|
|
78
|
+
|
|
79
|
+
## Type Declarations
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
export type UseDebounceFnReturn<T extends FunctionArgs> = PromisifyFn<T>
|
|
83
|
+
/**
|
|
84
|
+
* Debounce execution of a function.
|
|
85
|
+
*
|
|
86
|
+
* @see https://vueuse.org/useDebounceFn
|
|
87
|
+
* @param fn A function to be executed after delay milliseconds debounced.
|
|
88
|
+
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
|
89
|
+
* @param options Options
|
|
90
|
+
*
|
|
91
|
+
* @return A new, debounce, function.
|
|
92
|
+
*
|
|
93
|
+
* @__NO_SIDE_EFFECTS__
|
|
94
|
+
*/
|
|
95
|
+
export declare function useDebounceFn<T extends FunctionArgs>(
|
|
96
|
+
fn: T,
|
|
97
|
+
ms?: MaybeRefOrGetter<number>,
|
|
98
|
+
options?: DebounceFilterOptions,
|
|
99
|
+
): UseDebounceFnReturn<T>
|
|
100
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: State
|
|
3
|
+
related:
|
|
4
|
+
- useRefHistory
|
|
5
|
+
- useThrottledRefHistory
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# useDebouncedRefHistory
|
|
9
|
+
|
|
10
|
+
Shorthand for `useRefHistory` with debounced filter.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
This function takes a snapshot of your counter after 1000ms when the value of it starts to change.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { useDebouncedRefHistory } from '@vueuse/core'
|
|
18
|
+
import { shallowRef } from 'vue'
|
|
19
|
+
|
|
20
|
+
const counter = shallowRef(0)
|
|
21
|
+
const { history, undo, redo } = useDebouncedRefHistory(counter, { deep: true, debounce: 1000 })
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Type Declarations
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
/**
|
|
28
|
+
* Shorthand for [useRefHistory](https://vueuse.org/useRefHistory) with debounce filter.
|
|
29
|
+
*
|
|
30
|
+
* @see https://vueuse.org/useDebouncedRefHistory
|
|
31
|
+
* @param source
|
|
32
|
+
* @param options
|
|
33
|
+
*/
|
|
34
|
+
export declare function useDebouncedRefHistory<Raw, Serialized = Raw>(
|
|
35
|
+
source: Ref<Raw>,
|
|
36
|
+
options?: Omit<UseRefHistoryOptions<Raw, Serialized>, 'eventFilter'> & {
|
|
37
|
+
debounce?: MaybeRefOrGetter<number>
|
|
38
|
+
},
|
|
39
|
+
): UseRefHistoryReturn<Raw, Serialized>
|
|
40
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Sensors
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# useDeviceMotion
|
|
6
|
+
|
|
7
|
+
Reactive [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent). Provide web developers with information about the speed of changes for the device's position and orientation.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { useDeviceMotion } from '@vueuse/core'
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
acceleration,
|
|
16
|
+
accelerationIncludingGravity,
|
|
17
|
+
rotationRate,
|
|
18
|
+
interval,
|
|
19
|
+
} = useDeviceMotion()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> Note: For iOS, you need to use `trigger` and bind it with user interaction.
|
|
23
|
+
> After permission granted, the API will run automatically
|
|
24
|
+
|
|
25
|
+
| State | Type | Description |
|
|
26
|
+
| ---------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
27
|
+
| acceleration | `object` | An object giving the acceleration of the device on the three axis X, Y and Z. |
|
|
28
|
+
| accelerationIncludingGravity | `object` | An object giving the acceleration of the device on the three axis X, Y and Z with the effect of gravity. |
|
|
29
|
+
| rotationRate | `object` | An object giving the rate of change of the device's orientation on the three orientation axis alpha, beta and gamma. |
|
|
30
|
+
| interval | `Number` | A number representing the interval of time, in milliseconds, at which data is obtained from the device.. |
|
|
31
|
+
| ensurePermissions | `boolean` | Indicates whether the platform requires permission to use the API |
|
|
32
|
+
| permissionGranted | `boolean` | Indicates whether the user has granted permission. The default is always false |
|
|
33
|
+
| trigger | `Promise<void>` | An async function to request user permission. The API runs automatically once permission is granted |
|
|
34
|
+
|
|
35
|
+
You can find [more information about the state on the MDN](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent#instance_properties).
|
|
36
|
+
|
|
37
|
+
## Component Usage
|
|
38
|
+
|
|
39
|
+
```vue
|
|
40
|
+
<template>
|
|
41
|
+
<UseDeviceMotion v-slot="{ acceleration }">
|
|
42
|
+
Acceleration: {{ acceleration }}
|
|
43
|
+
</UseDeviceMotion>
|
|
44
|
+
</template>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Type Declarations
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
export interface DeviceMotionOptions
|
|
51
|
+
extends ConfigurableWindow, ConfigurableEventFilter {
|
|
52
|
+
/**
|
|
53
|
+
* Request for permissions immediately if it's not granted,
|
|
54
|
+
* otherwise label and deviceIds could be empty
|
|
55
|
+
*
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
requestPermissions?: boolean
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reactive DeviceMotionEvent.
|
|
62
|
+
*
|
|
63
|
+
* @see https://vueuse.org/useDeviceMotion
|
|
64
|
+
* @param options
|
|
65
|
+
*/
|
|
66
|
+
export declare function useDeviceMotion(options?: DeviceMotionOptions): {
|
|
67
|
+
acceleration: Ref<
|
|
68
|
+
DeviceMotionEventAcceleration | null,
|
|
69
|
+
DeviceMotionEventAcceleration | null
|
|
70
|
+
>
|
|
71
|
+
accelerationIncludingGravity: Ref<
|
|
72
|
+
DeviceMotionEventAcceleration | null,
|
|
73
|
+
DeviceMotionEventAcceleration | null
|
|
74
|
+
>
|
|
75
|
+
rotationRate: Ref<
|
|
76
|
+
DeviceMotionEventRotationRate | null,
|
|
77
|
+
DeviceMotionEventRotationRate | null
|
|
78
|
+
>
|
|
79
|
+
interval: ShallowRef<number, number>
|
|
80
|
+
isSupported: ComputedRef<boolean>
|
|
81
|
+
requirePermissions: ComputedRef<boolean>
|
|
82
|
+
ensurePermissions: () => Promise<void>
|
|
83
|
+
permissionGranted: ShallowRef<boolean, boolean>
|
|
84
|
+
}
|
|
85
|
+
export type UseDeviceMotionReturn = ReturnType<typeof useDeviceMotion>
|
|
86
|
+
```
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Sensors
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# useDeviceOrientation
|
|
6
|
+
|
|
7
|
+
Reactive [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent). Provide web developers with information from the physical orientation of the device running the web page.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { useDeviceOrientation } from '@vueuse/core'
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
isAbsolute,
|
|
16
|
+
alpha,
|
|
17
|
+
beta,
|
|
18
|
+
gamma,
|
|
19
|
+
} = useDeviceOrientation()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
| State | Type | Description |
|
|
23
|
+
| ---------- | --------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| isAbsolute | `boolean` | A boolean that indicates whether or not the device is providing orientation data absolutely. |
|
|
25
|
+
| alpha | `number` | A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360. |
|
|
26
|
+
| beta | `number` | A number representing the motion of the device around the x axis, express in degrees with values ranging from -180 to 180. |
|
|
27
|
+
| gamma | `number` | A number representing the motion of the device around the y axis, express in degrees with values ranging from -90 to 90. |
|
|
28
|
+
|
|
29
|
+
You can find [more information about the state on the MDN](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent#instance_properties).
|
|
30
|
+
|
|
31
|
+
## Component Usage
|
|
32
|
+
|
|
33
|
+
```vue
|
|
34
|
+
<template>
|
|
35
|
+
<UseDeviceOrientation v-slot="{ alpha, beta, gamma }">
|
|
36
|
+
Alpha: {{ alpha }}
|
|
37
|
+
Beta: {{ beta }}
|
|
38
|
+
Gamma: {{ gamma }}
|
|
39
|
+
</UseDeviceOrientation>
|
|
40
|
+
</template>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Type Declarations
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
/**
|
|
47
|
+
* Reactive DeviceOrientationEvent.
|
|
48
|
+
*
|
|
49
|
+
* @see https://vueuse.org/useDeviceOrientation
|
|
50
|
+
* @param options
|
|
51
|
+
*
|
|
52
|
+
* @__NO_SIDE_EFFECTS__
|
|
53
|
+
*/
|
|
54
|
+
export declare function useDeviceOrientation(options?: ConfigurableWindow): {
|
|
55
|
+
isSupported: ComputedRef<boolean>
|
|
56
|
+
isAbsolute: ShallowRef<boolean, boolean>
|
|
57
|
+
alpha: Ref<number | null, number | null>
|
|
58
|
+
beta: Ref<number | null, number | null>
|
|
59
|
+
gamma: Ref<number | null, number | null>
|
|
60
|
+
}
|
|
61
|
+
export type UseDeviceOrientationReturn = ReturnType<typeof useDeviceOrientation>
|
|
62
|
+
```
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Sensors
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# useDevicePixelRatio
|
|
6
|
+
|
|
7
|
+
Reactively track [`window.devicePixelRatio`](https://developer.mozilla.org/docs/Web/API/Window/devicePixelRatio)
|
|
8
|
+
|
|
9
|
+
> NOTE: there is no event listener for `window.devicePixelRatio` change. So this function uses [`Testing media queries programmatically (window.matchMedia)`](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Testing_media_queries) applying the same mechanism as described in [this example](https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes).
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { useDevicePixelRatio } from '@vueuse/core'
|
|
15
|
+
|
|
16
|
+
const { pixelRatio } = useDevicePixelRatio()
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Component Usage
|
|
20
|
+
|
|
21
|
+
```vue
|
|
22
|
+
<template>
|
|
23
|
+
<UseDevicePixelRatio v-slot="{ pixelRatio }">
|
|
24
|
+
Pixel Ratio: {{ pixelRatio }}
|
|
25
|
+
</UseDevicePixelRatio>
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Type Declarations
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
/**
|
|
33
|
+
* Reactively track `window.devicePixelRatio`.
|
|
34
|
+
*
|
|
35
|
+
* @see https://vueuse.org/useDevicePixelRatio
|
|
36
|
+
*
|
|
37
|
+
* @__NO_SIDE_EFFECTS__
|
|
38
|
+
*/
|
|
39
|
+
export declare function useDevicePixelRatio(options?: ConfigurableWindow): {
|
|
40
|
+
pixelRatio: Readonly<Ref<number, number>>
|
|
41
|
+
stop: WatchStopHandle
|
|
42
|
+
}
|
|
43
|
+
export type UseDevicePixelRatioReturn = ReturnType<typeof useDevicePixelRatio>
|
|
44
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Sensors
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# useDevicesList
|
|
6
|
+
|
|
7
|
+
Reactive [enumerateDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices) listing available input/output devices.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { useDevicesList } from '@vueuse/core'
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
devices,
|
|
16
|
+
videoInputs: cameras,
|
|
17
|
+
audioInputs: microphones,
|
|
18
|
+
audioOutputs: speakers,
|
|
19
|
+
} = useDevicesList()
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Requesting Permissions
|
|
23
|
+
|
|
24
|
+
To request permissions, use the `ensurePermissions` method.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { useDevicesList } from '@vueuse/core'
|
|
28
|
+
// ---cut---
|
|
29
|
+
const {
|
|
30
|
+
ensurePermissions,
|
|
31
|
+
permissionGranted,
|
|
32
|
+
} = useDevicesList()
|
|
33
|
+
|
|
34
|
+
await ensurePermissions()
|
|
35
|
+
console.log(permissionsGranted.value)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Component
|
|
39
|
+
|
|
40
|
+
```vue
|
|
41
|
+
<template>
|
|
42
|
+
<UseDevicesList v-slot="{ videoInputs, audioInputs, audioOutputs }">
|
|
43
|
+
Cameras: {{ videoInputs }}
|
|
44
|
+
Microphones: {{ audioInputs }}
|
|
45
|
+
Speakers: {{ audioOutputs }}
|
|
46
|
+
</UseDevicesList>
|
|
47
|
+
</template>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Type Declarations
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
export interface UseDevicesListOptions extends ConfigurableNavigator {
|
|
54
|
+
onUpdated?: (devices: MediaDeviceInfo[]) => void
|
|
55
|
+
/**
|
|
56
|
+
* Request for permissions immediately if it's not granted,
|
|
57
|
+
* otherwise label and deviceIds could be empty
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
requestPermissions?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* Request for types of media permissions
|
|
64
|
+
*
|
|
65
|
+
* @default { audio: true, video: true }
|
|
66
|
+
*/
|
|
67
|
+
constraints?: MediaStreamConstraints
|
|
68
|
+
}
|
|
69
|
+
export interface UseDevicesListReturn {
|
|
70
|
+
/**
|
|
71
|
+
* All devices
|
|
72
|
+
*/
|
|
73
|
+
devices: Ref<MediaDeviceInfo[]>
|
|
74
|
+
videoInputs: ComputedRef<MediaDeviceInfo[]>
|
|
75
|
+
audioInputs: ComputedRef<MediaDeviceInfo[]>
|
|
76
|
+
audioOutputs: ComputedRef<MediaDeviceInfo[]>
|
|
77
|
+
permissionGranted: ShallowRef<boolean>
|
|
78
|
+
ensurePermissions: () => Promise<boolean>
|
|
79
|
+
isSupported: ComputedRef<boolean>
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reactive `enumerateDevices` listing available input/output devices
|
|
83
|
+
*
|
|
84
|
+
* @see https://vueuse.org/useDevicesList
|
|
85
|
+
* @param options
|
|
86
|
+
*/
|
|
87
|
+
export declare function useDevicesList(
|
|
88
|
+
options?: UseDevicesListOptions,
|
|
89
|
+
): UseDevicesListReturn
|
|
90
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Sensors
|
|
3
|
+
related: useUserMedia
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# useDisplayMedia
|
|
7
|
+
|
|
8
|
+
Reactive [`mediaDevices.getDisplayMedia`](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia) streaming.
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```vue
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
import { useDisplayMedia } from '@vueuse/core'
|
|
15
|
+
import { useTemplateRef } from 'vue'
|
|
16
|
+
|
|
17
|
+
const { stream, start } = useDisplayMedia()
|
|
18
|
+
|
|
19
|
+
// start streaming
|
|
20
|
+
start()
|
|
21
|
+
|
|
22
|
+
const videoRef = useTemplateRef('video')
|
|
23
|
+
watchEffect(() => {
|
|
24
|
+
// preview on a video element
|
|
25
|
+
videoRef.value.srcObject = stream.value
|
|
26
|
+
})
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<video ref="video" />
|
|
31
|
+
</template>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Type Declarations
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
export interface UseDisplayMediaOptions extends ConfigurableNavigator {
|
|
38
|
+
/**
|
|
39
|
+
* If the stream is enabled
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
enabled?: MaybeRef<boolean>
|
|
43
|
+
/**
|
|
44
|
+
* If the stream video media constraints
|
|
45
|
+
*/
|
|
46
|
+
video?: boolean | MediaTrackConstraints | undefined
|
|
47
|
+
/**
|
|
48
|
+
* If the stream audio media constraints
|
|
49
|
+
*/
|
|
50
|
+
audio?: boolean | MediaTrackConstraints | undefined
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Reactive `mediaDevices.getDisplayMedia` streaming
|
|
54
|
+
*
|
|
55
|
+
* @see https://vueuse.org/useDisplayMedia
|
|
56
|
+
* @param options
|
|
57
|
+
*/
|
|
58
|
+
export declare function useDisplayMedia(options?: UseDisplayMediaOptions): {
|
|
59
|
+
isSupported: ComputedRef<boolean>
|
|
60
|
+
stream: ShallowRef<MediaStream | undefined, MediaStream | undefined>
|
|
61
|
+
start: () => Promise<MediaStream | undefined>
|
|
62
|
+
stop: () => void
|
|
63
|
+
enabled:
|
|
64
|
+
| Ref<boolean, boolean>
|
|
65
|
+
| ShallowRef<boolean, boolean>
|
|
66
|
+
| WritableComputedRef<boolean, boolean>
|
|
67
|
+
| ShallowRef<true, true>
|
|
68
|
+
| ShallowRef<false, false>
|
|
69
|
+
}
|
|
70
|
+
export type UseDisplayMediaReturn = ReturnType<typeof useDisplayMedia>
|
|
71
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
category: Elements
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# useDocumentVisibility
|
|
6
|
+
|
|
7
|
+
Reactively track [`document.visibilityState`](https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState)
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```vue
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
import { useDocumentVisibility } from '@vueuse/core'
|
|
14
|
+
|
|
15
|
+
const visibility = useDocumentVisibility()
|
|
16
|
+
</script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Component Usage
|
|
20
|
+
|
|
21
|
+
```vue
|
|
22
|
+
<template>
|
|
23
|
+
<UseDocumentVisibility v-slot="{ visibility }">
|
|
24
|
+
Document Visibility: {{ visibility }}
|
|
25
|
+
</UseDocumentVisibility>
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Type Declarations
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
/**
|
|
33
|
+
* Reactively track `document.visibilityState`.
|
|
34
|
+
*
|
|
35
|
+
* @see https://vueuse.org/useDocumentVisibility
|
|
36
|
+
*
|
|
37
|
+
* @__NO_SIDE_EFFECTS__
|
|
38
|
+
*/
|
|
39
|
+
export declare function useDocumentVisibility(
|
|
40
|
+
options?: ConfigurableDocument,
|
|
41
|
+
): ShallowRef<DocumentVisibilityState, DocumentVisibilityState>
|
|
42
|
+
export type UseDocumentVisibilityReturn = ReturnType<
|
|
43
|
+
typeof useDocumentVisibility
|
|
44
|
+
>
|
|
45
|
+
```
|