跳到主要内容

useEyeDropper

分类
导出大小
283 B
上次更改
3 个月前

响应式的 EyeDropper API

演示

您的浏览器不支持此功能

用法

ts
import { 
useEyeDropper
} from '@vueuse/core'
const {
isSupported
,
open
,
sRGBHex
} =
useEyeDropper
()

组件用法

此函数还通过 @vueuse/components 包提供了一个无渲染组件版本。了解更多用法

vue
<template>
  <UseEyeDropper v-slot="{ 
isSupported
,
sRGBHex
,
open
}">
<
button
:disabled
="!
isSupported
" @
click
="() =>
open
()">
sRGBHex: {{
sRGBHex
}}
</
button
>
</UseEyeDropper> </template>

类型声明

ts
export interface EyeDropperOpenOptions {
  /**
   * @see https://mdn.org.cn/en-US/docs/Web/API/AbortSignal
   */
  
signal
?: AbortSignal
} export interface EyeDropper { new (): EyeDropper
open
: (
options
?: EyeDropperOpenOptions) =>
Promise
<{
sRGBHex
: string
}> [
Symbol
.
toStringTag
]: "EyeDropper"
} export interface UseEyeDropperOptions { /** * Initial sRGBHex. * * @default '' */
initialValue
?: string
} /** * Reactive [EyeDropper API](https://mdn.org.cn/en-US/docs/Web/API/EyeDropper_API) * * @see https://vueuse.org.cn/useEyeDropper * * @__NO_SIDE_EFFECTS__ */ export declare function
useEyeDropper
(
options
?: UseEyeDropperOptions): {
isSupported
:
ComputedRef
<boolean>
sRGBHex
:
ShallowRef
<string, string>
open
: (
openOptions
?: EyeDropperOpenOptions) =>
Promise
<
| {
sRGBHex
: string
} | undefined > } export type
UseEyeDropperReturn
=
ReturnType
<typeof
useEyeDropper
>

来源

源代码演示文档

贡献者

Anthony Fu
Jelf
Anthony Fu
IlyaL
SerKo
vaakian X
wheat

更新日志

8c521 - feat(components)!: 重构组件并使其保持一致 (#4912)
v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。