Files
fuel-price/.agents/skills/vueuse-functions/references/useScreenOrientation.md
Ovidiu U 4a3ce4cc1d
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
docs: add advanced skills for Vitest, Pinia, and Vue built-ins
Add comprehensive reference documentation for:
- Vitest: environments, projects/workspaces, type testing, vi utilities
- Pinia: HMR, Nuxt integration, SSR setup
- Vue: built-in components (Transition, Teleport, Suspense, KeepAlive) and advanced directives
2026-04-11 16:28:36 +01:00

99 lines
2.5 KiB
Markdown

---
category: Browser
---
# useScreenOrientation
Reactive [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.
## Usage
```ts
import { useScreenOrientation } from '@vueuse/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()
```
To lock the orientation, you can pass an [OrientationLockType](https://developer.mozilla.org/en-US/docs/Web/API/ScreenOrientation/type) to the lockOrientation function:
```ts
import { useScreenOrientation } from '@vueuse/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()
lockOrientation('portrait-primary')
```
and then unlock again, with the following:
```ts
import { useScreenOrientation } from '@vueuse/core'
const { unlockOrientation } = useScreenOrientation()
// ---cut---
unlockOrientation()
```
Accepted orientation types are one of `"landscape-primary"`, `"landscape-secondary"`, `"portrait-primary"`, `"portrait-secondary"`, `"any"`, `"landscape"`, `"natural"` and `"portrait"`.
[Screen Orientation API MDN](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Orientation_API)
## Type Declarations
```ts
export type OrientationType =
| "portrait-primary"
| "portrait-secondary"
| "landscape-primary"
| "landscape-secondary"
export type OrientationLockType =
| "any"
| "natural"
| "landscape"
| "portrait"
| "portrait-primary"
| "portrait-secondary"
| "landscape-primary"
| "landscape-secondary"
export interface ScreenOrientation extends EventTarget {
lock: (orientation: OrientationLockType) => Promise<void>
unlock: () => void
readonly type: OrientationType
readonly angle: number
addEventListener: (
type: "change",
listener: (this: this, ev: Event) => any,
useCapture?: boolean,
) => void
}
export interface UseScreenOrientationOptions extends ConfigurableWindow {}
export interface UseScreenOrientationReturn extends Supportable {
orientation: Ref<OrientationType | undefined>
angle: ShallowRef<number>
lockOrientation: (type: OrientationLockType) => Promise<void>
unlockOrientation: () => void
}
/**
* Reactive screen orientation
*
* @see https://vueuse.org/useScreenOrientation
*
* @__NO_SIDE_EFFECTS__
*/
export declare function useScreenOrientation(
options?: UseScreenOrientationOptions,
): UseScreenOrientationReturn
```