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/useDevicePixelRatio.md
1---2category: Sensors3---45# useDevicePixelRatio67Reactively track [`window.devicePixelRatio`](https://developer.mozilla.org/docs/Web/API/Window/devicePixelRatio)89> 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).1011## Usage1213```ts14import { useDevicePixelRatio } from '@vueuse/core'1516const { pixelRatio } = useDevicePixelRatio()17```1819## Component Usage2021```vue22<template>23<UseDevicePixelRatio v-slot="{ pixelRatio }">24Pixel Ratio: {{ pixelRatio }}25</UseDevicePixelRatio>26</template>27```2829## Type Declarations3031```ts32export interface UseDevicePixelRatioOptions extends ConfigurableWindow {}33export interface UseDevicePixelRatioReturn {34pixelRatio: ShallowRef<number>35stop: WatchStopHandle36}37/**38* Reactively track `window.devicePixelRatio`.39*40* @see https://vueuse.org/useDevicePixelRatio41*42* @__NO_SIDE_EFFECTS__43*/44export declare function useDevicePixelRatio(45options?: UseDevicePixelRatioOptions,46): UseDevicePixelRatioReturn47```48