Skip to content

usePermission

Category
Export Size
759 B
Last Changed
15 minutes ago
Related

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

Demo

用法

js
import { usePermission } from '@vueuse/core'

const microphoneAccess = usePermission('microphone')

类型声明

显示类型声明
typescript
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<Ref<PermissionState | undefined>>
export interface UsePermissionReturnWithControls {
  state: UsePermissionReturn
  isSupported: Ref<boolean>
  query: () => Promise<PermissionStatus | undefined>
}
/**
 * Reactive Permissions API.
 *
 * @see https://vueuse.org/usePermission
 */
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options?: UsePermissionOptions<false>,
): UsePermissionReturn
export declare function usePermission(
  permissionDesc:
    | GeneralPermissionDescriptor
    | GeneralPermissionDescriptor["name"],
  options: UsePermissionOptions<true>,
): UsePermissionReturnWithControls

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
Fernando Fernández
Antério Vieira
Anthony Fu
sean
Jelf
Guille
Alex Kozack
Nurettin Kaya

变更日志

v11.0.2 on 8/24/2024
2aaa1 - fix: state setting (#4167)
v11.0.1 on 8/19/2024
63a22 - fix: fix memory leak (#4157)
v11.0.0-beta.2 on 7/17/2024
5f584 - feat: add local-fonts permission (#4098)

Released under the MIT License.