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/useScreenOrientation.md
1---2category: Browser3---45# useScreenOrientation67Reactive [Screen Orientation API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Orientation_API). It provides web developers with information about the user's current screen orientation.89## Usage1011```ts12import { useScreenOrientation } from '@vueuse/core'1314const {15isSupported,16orientation,17angle,18lockOrientation,19unlockOrientation,20} = useScreenOrientation()21```2223To lock the orientation, you can pass an [OrientationLockType](https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/type) to the lockOrientation function:2425```ts26import { useScreenOrientation } from '@vueuse/core'2728const {29isSupported,30orientation,31angle,32lockOrientation,33unlockOrientation,34} = useScreenOrientation()3536lockOrientation('portrait-primary')37```3839and then unlock again, with the following:4041```ts42import { useScreenOrientation } from '@vueuse/core'4344const { unlockOrientation } = useScreenOrientation()45// ---cut---46unlockOrientation()47```4849Accepted orientation types are one of `"landscape-primary"`, `"landscape-secondary"`, `"portrait-primary"`, `"portrait-secondary"`, `"any"`, `"landscape"`, `"natural"` and `"portrait"`.5051[Screen Orientation API MDN](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Orientation_API)5253## Type Declarations5455```ts56export type OrientationType =57| "portrait-primary"58| "portrait-secondary"59| "landscape-primary"60| "landscape-secondary"61export type OrientationLockType =62| "any"63| "natural"64| "landscape"65| "portrait"66| "portrait-primary"67| "portrait-secondary"68| "landscape-primary"69| "landscape-secondary"70export interface ScreenOrientation extends EventTarget {71lock: (orientation: OrientationLockType) => Promise<void>72unlock: () => void73readonly type: OrientationType74readonly angle: number75addEventListener: (76type: "change",77listener: (this: this, ev: Event) => any,78useCapture?: boolean,79) => void80}81export interface UseScreenOrientationOptions extends ConfigurableWindow {}82export interface UseScreenOrientationReturn extends Supportable {83orientation: Ref<OrientationType | undefined>84angle: ShallowRef<number>85lockOrientation: (type: OrientationLockType) => Promise<void>86unlockOrientation: () => void87}88/**89* Reactive screen orientation90*91* @see https://vueuse.org/useScreenOrientation92*93* @__NO_SIDE_EFFECTS__94*/95export declare function useScreenOrientation(96options?: UseScreenOrientationOptions,97): UseScreenOrientationReturn98```99