useMediaQuery
响应式的 媒体查询。一旦您创建了一个 MediaQueryList 对象,您可以检查查询结果或在结果变化时接收通知。
Demo
isLargeScreen: false
prefersDark: false
使用方法
js
import { useMediaQuery } from '@vueuse/core'
const isLargeScreen = useMediaQuery('(min-width: 1024px)')
const isPreferredDark = useMediaQuery('(prefers-color-scheme: dark)')
类型声明
typescript
/**
* 响应式媒体查询。
*
* @see https://vueuse.org/useMediaQuery
* @param query
* @param options
*/
export declare function useMediaQuery(
query: MaybeRefOrGetter<string>,
options?: ConfigurableWindow,
): Ref<boolean, boolean>
Source
贡献者
Anthony Fu
Antério Vieira
丶远方
Anthony Fu
Indrek Ardel
Zhousg
Young
Jelf
Dominik Freier
webfansplz
Eureka
karma
Alex Kozack
Jacob Clevenger
变更日志
v10.3.0
on 7/30/2023v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
10e98
- feat(toRef)!: rename resolveRef
to toRef
v10.0.0-beta.3
on 4/12/2023