Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useVibrate.md
1---2category: Browser3---45# useVibrate67Reactive [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API)89Most modern mobile devices include vibration hardware, which lets software10code provides physical feedback to the user by causing the device to shake.1112The Vibration API offers Web apps the ability to access this hardware,13if it exists, and does nothing if the device doesn't support it.1415## Usage1617Vibration is described as a pattern of on-off pulses, which may be of varying18lengths.1920The pattern may consist of either a single integer describing the21number of milliseconds to vibrate, or an array of integers describing22a pattern of vibrations and pauses.2324```ts25import { useVibrate } from '@vueuse/core'2627// This vibrates the device for 300 ms28// then pauses for 100 ms before vibrating the device again for another 300 ms:29const { vibrate, stop, isSupported } = useVibrate({ pattern: [300, 100, 300] })3031// Start the vibration, it will automatically stop when the pattern is complete:32vibrate()3334// But if you want to stop it, you can:35stop()36```3738## Type Declarations3940```ts41export interface UseVibrateOptions42extends ConfigurableNavigator, ConfigurableScheduler {43/**44*45* Vibration Pattern46*47* An array of values describes alternating periods in which the48* device is vibrating and not vibrating. Each value in the array49* is converted to an integer, then interpreted alternately as50* the number of milliseconds the device should vibrate and the51* number of milliseconds it should not be vibrating52*53* @default []54*55*/56pattern?: MaybeRefOrGetter<Arrayable<number>>57/**58* Interval to run a persistent vibration, in ms59*60* Pass `0` to disable61*62* @deprecated Please use `scheduler` option instead63* @default 064*65*/66interval: number67}68export interface UseVibrateReturn extends Supportable {69pattern: MaybeRefOrGetter<Arrayable<number>>70intervalControls?: Pausable71vibrate: (pattern?: Arrayable<number>) => void72stop: () => void73}74/**75* Reactive vibrate76*77* @see https://vueuse.org/useVibrate78* @see https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API79* @param options80*81* @__NO_SIDE_EFFECTS__82*/83export declare function useVibrate(84options?: UseVibrateOptions,85): UseVibrateReturn86```87