主题
useWakeLock
响应式 屏幕唤醒锁 API。提供了一种方法,可以在应用需要持续运行时防止设备屏幕变暗或锁定。
🌐 Reactive Screen Wake Lock API. Provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.
示例
用法
🌐 Usage
ts
import { useWakeLock } from '@vueuse/core'
const { isSupported, isActive, forceRequest, request, release } = useWakeLock()当调用 request 时,如果文档可见,将请求唤醒锁。否则,请求将被排队,直到文档变为可见。如果请求成功,isActive 将是 true。每当文档被隐藏时,isActive 将是 false。
🌐 When request is called, the wake lock will be requested if the document is visible. Otherwise, the request will be queued until the document becomes visible. If the request is successful, isActive will be true. Whenever the document is hidden, the isActive will be false.
当调用 release 时,唤醒锁将被释放。如果有排队的请求,它将被取消。
🌐 When release is called, the wake lock will be released. If there is a queued request, it will be canceled.
要立即请求唤醒锁,即使文档处于隐藏状态,也可以使用 forceRequest。请注意,如果文档是隐藏的,可能会抛出错误。
🌐 To request a wake lock immediately, even if the document is hidden, use forceRequest. Note that this may throw an error if the document is hidden.