Skip to content

useDevicePixelRatio

Category
Export Size
1.23 kB
Last Changed
4 weeks ago

Reactively track window.devicePixelRatio

NOTE: there is no event listener for window.devicePixelRatio change. So this function uses Testing media queries programmatically (window.matchMedia) applying the same mechanism as described in this example.

Demo

Device Pixel Ratio:
pixelRatio: 1
Zoom in and out (or move the window to a screen with a different scaling factor) to see the value changes

Usage

ts
import { 
useDevicePixelRatio
} from '@vueuse/core'
const {
pixelRatio
} =
useDevicePixelRatio
()

Component Usage

This function also provides a renderless component version via the @vueuse/components package. Learn more about the usage.

vue
<template>
  <UseDevicePixelRatio v-slot="{ 
pixelRatio
}">
Pixel Ratio: {{
pixelRatio
}}
</UseDevicePixelRatio> </template>

Type Declarations

ts
export interface UseDevicePixelRatioOptions extends ConfigurableWindow {}
export interface UseDevicePixelRatioReturn {
  
pixelRatio
:
ShallowRef
<number>
stop
:
WatchStopHandle
} /** * Reactively track `window.devicePixelRatio`. * * @see https://vueuse.org/useDevicePixelRatio * * @__NO_SIDE_EFFECTS__ */ export declare function
useDevicePixelRatio
(
options
?: UseDevicePixelRatioOptions,
): UseDevicePixelRatioReturn

Source

SourceDemoDocs

Contributors

Anthony Fu
Antério Vieira
SerKo
Anthony Fu
Waleed Khaled
wheat
Vida Xie
IlyaL
Yu Lia
Robin
Fernando Fernández
David Hewson
vaakian X
Shinigami
Alex Kozack
Konstantin Barabanov

Changelog

8c521 - feat(components)!: refactor components and make them consistent (#4912)
1b3d4 - feat: improve types (#4927)
d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)