主题
useArrayIncludes
反应式 Array.includes
¥Reactive Array.includes
用法
¥Usage
与反应式数组一起使用
¥Use with reactive array
js
import { useArrayIncludes } from '@vueuse/core'
const list = ref([0, 2, 4, 6, 8])
const result = useArrayIncludes(list, 10)
// result.value: false
list.value.push(10)
// result.value: true
list.value.pop()
// result.value: false
类型声明
显示类型声明
typescript
export type UseArrayIncludesComparatorFn<T, V> = (
element: T,
value: V,
index: number,
array: MaybeRefOrGetter<T>[],
) => boolean
export interface UseArrayIncludesOptions<T, V> {
fromIndex?: number
comparator?: UseArrayIncludesComparatorFn<T, V> | keyof T
}
/**
* Reactive `Array.includes`
*
* @see https://vueuse.org/useArrayIncludes
*
* @returns true if the `value` is found in the array. Otherwise, false.
*/
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
comparator?: UseArrayIncludesComparatorFn<T, V>,
): ComputedRef<boolean>
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
comparator?: keyof T,
): ComputedRef<boolean>
export declare function useArrayIncludes<T, V = any>(
list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
value: MaybeRefOrGetter<V>,
options?: UseArrayIncludesOptions<T, V>,
): ComputedRef<boolean>