Skip to content

usePermission ​

类别
导出体积
883 B
上次更改
6 months ago
相关

响应式的权限 API。权限 API 提供了工具,使开发人员能够在权限方面实现更好的用户体验。

示例 ​

用法 ​

ts
import { 
usePermission
} from '@vueuse/core'
const
microphoneAccess
=
usePermission
('microphone')

类型声明 ​

显示类型声明
ts
type 
DescriptorNamePolyfill
=
| "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "notifications" | "payment-handler" | "persistent-storage" | "push" | "speaker" | "local-fonts" export type
GeneralPermissionDescriptor
=
| PermissionDescriptor | {
name
:
DescriptorNamePolyfill
} export interface
UsePermissionOptions
<
Controls
extends boolean,
> extends ConfigurableNavigator { /** * return 更多属性 * * @default false */
controls
?:
Controls
} export type
UsePermissionReturn
=
Readonly
<
ShallowRef
<
PermissionState
| undefined>
> export interface UsePermissionReturnWithControls extends Supportable {
state
:
UsePermissionReturn
query
: () =>
Promise
<PermissionStatus | undefined>
} /** * Reactive Permissions API. * * @see https://vueuse.org/usePermission * * @__NO_SIDE_EFFECTS__ */ export declare function
usePermission
(
permissionDesc
:
GeneralPermissionDescriptor
|
GeneralPermissionDescriptor
["name"],
options
?:
UsePermissionOptions
<false>,
):
UsePermissionReturn
export declare function
usePermission
(
permissionDesc
:
GeneralPermissionDescriptor
|
GeneralPermissionDescriptor
["name"],
options
:
UsePermissionOptions
<true>,
): UsePermissionReturnWithControls

源码 ​

源码 • 演示 • 文档

贡献者 ​

Anthony Fu
一纸忘忧
Anthony Fu
Fernando Fernández
SerKo
Antério Vieira
Vida Xie
Robin
James Garbutt
IlyaL
Alex Liu
Damon Muma
sean
Jelf
Guille
Alex Kozack
Nurettin Kaya

更新日志 ​

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
dd316 - feat: use passive event handlers everywhere is possible (#4477)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
2aaa1 - fix: state setting (#4167)
63a22 - fix: fix memory leak (#4157)
5f584 - feat: add local-fonts permission (#4098)