useScreenOrientation
响应式Screen Orientation API。它为web开发者提供有关用户当前屏幕方向的信息。
Reactive 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()
import { useScreenOrientation } from '@vueuse/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()
如果要锁定方向,您可以将 OrientationLockType 传递给 lockOrientation 函数。
To lock the orientation, you can pass an OrientationLockType to the lockOrientation function:
ts
import { useScreenOrientation } from '@vueuse/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()
lockOrientation('portrait-primary')
import { useScreenOrientation } from '@vueuse/core'
const {
isSupported,
orientation,
angle,
lockOrientation,
unlockOrientation,
} = useScreenOrientation()
lockOrientation('portrait-primary')
然后再次解锁,使用以下命令:
and then unlock again, with the following:
ts
unlockOrientation()
unlockOrientation()
接受的方向类型是以下类型之一,"landscape-primary"
, "landscape-secondary"
, "portrait-primary"
, "portrait-secondary"
, "any"
, "landscape"
, "natural"
和 "portrait"
.
Accepted orientation types are one of "landscape-primary"
, "landscape-secondary"
, "portrait-primary"
, "portrait-secondary"
, "any"
, "landscape"
, "natural"
and "portrait"
.
Type Declarations
typescript
/**
* Reactive screen orientation
*
* @see https://vueuse.org/useScreenOrientation
*/
export declare const useScreenOrientation: (options?: ConfigurableWindow) => {
isSupported: Ref<boolean>
orientation: Ref<OrientationType | undefined>
angle: Ref<number>
lockOrientation: (type: OrientationLockType) => Promise<void>
unlockOrientation: () => void
}
export type UseScreenOrientationReturn = ReturnType<typeof useScreenOrientation>
/**
* Reactive screen orientation
*
* @see https://vueuse.org/useScreenOrientation
*/
export declare const useScreenOrientation: (options?: ConfigurableWindow) => {
isSupported: Ref<boolean>
orientation: Ref<OrientationType | undefined>
angle: Ref<number>
lockOrientation: (type: OrientationLockType) => Promise<void>
unlockOrientation: () => void
}
export type UseScreenOrientationReturn = ReturnType<typeof useScreenOrientation>