Vue 通过 VueUse 的 useDevicePixelRatio 来获取屏幕像素比。
import { useDevicePixelRatio } from '@vueuse/core'
const { pixelRatio } = useDevicePixelRatio()
<script setup lang="ts">
import { ref } from 'vue'
import { UseDevicePixelRatio } from '@vueuse/components'
</script>
<template>
<UseDevicePixelRatio v-slot="{ pixelRatio }">
Pixel Ratio: {{ pixelRatio }}
</UseDevicePixelRatio>
</template>
例子
/**
* Reactively track `window.devicePixelRatio`.
*
* @see https://vueuse.org/useDevicePixelRatio
*/
export declare function useDevicePixelRatio(options?: ConfigurableWindow): {
pixelRatio: Ref<number>
}
export type UseDevicePixelRatioReturn = ReturnType<typeof useDevicePixelRatio>