跳到主要内容

usePermission

分类
导出大小
941 B
上次更改
3 个月前
相关

响应式 Permissions API。Permissions 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 { /** * Expose more controls * * @default false */
controls
?:
Controls
} export type
UsePermissionReturn
=
Readonly
<
ShallowRef
<
PermissionState
| undefined>
> export interface UsePermissionReturnWithControls {
state
:
UsePermissionReturn
isSupported
:
ComputedRef
<boolean>
query
: () =>
Promise
<PermissionStatus | undefined>
} /** * Reactive Permissions API. * * @see https://vueuse.org.cn/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
Fernando Fernández
SerKo
Anthony Fu
Antério Vieira
Robin
James Garbutt
IlyaL
Alex Liu
Damon Muma
sean
Jelf
Guille
Alex Kozack
Nurettin Kaya

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.4.0
dd316 - feat: 尽可能在所有地方使用被动事件处理程序 (#4477)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v11.0.2
2aaa1 - 修复:状态设置 (#4167)
v11.0.1
63a22 - 修复:内存泄漏 (#4157)
5f584 - 特性:添加 local-fonts 权限 (#4098)

根据 MIT 许可证发布。