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/useDeviceMotion.md
1---2category: Sensors3---45# useDeviceMotion67Reactive [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.89## Usage1011```ts12import { useDeviceMotion } from '@vueuse/core'1314const {15acceleration,16accelerationIncludingGravity,17rotationRate,18interval,19} = useDeviceMotion()20```2122> Note: For iOS, you need to use `trigger` and bind it with user interaction.23> After permission granted, the API will run automatically2425| 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 |3435You can find [more information about the state on the MDN](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent#instance_properties).3637## Component Usage3839```vue40<template>41<UseDeviceMotion v-slot="{ acceleration }">42Acceleration: {{ acceleration }}43</UseDeviceMotion>44</template>45```4647## Type Declarations4849```ts50export interface UseDeviceMotionOptions51extends ConfigurableWindow, ConfigurableEventFilter {52/**53* Request for permissions immediately if it's not granted,54* otherwise label and deviceIds could be empty55*56* @default false57*/58requestPermissions?: boolean59}60/** @deprecated use {@link UseDeviceMotionOptions} instead */61export type DeviceMotionOptions = UseDeviceMotionOptions62export interface UseDeviceMotionReturn extends Supportable {63acceleration: Ref<DeviceMotionEventAcceleration | null>64accelerationIncludingGravity: Ref<DeviceMotionEventAcceleration | null>65rotationRate: Ref<DeviceMotionEventRotationRate | null>66interval: ShallowRef<number>67requirePermissions: ComputedRef<boolean>68ensurePermissions: () => Promise<void>69permissionGranted: ShallowRef<boolean>70}71/**72* Reactive DeviceMotionEvent.73*74* @see https://vueuse.org/useDeviceMotion75* @param options76*/77export declare function useDeviceMotion(78options?: UseDeviceMotionOptions,79): UseDeviceMotionReturn80```81