useArrayIncludes
响应式 Array.includes
。
用法
与响应式数组一起使用
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
}
/**
* 响应式 `Array.includes`
*
* @see https://vueuse.org/useArrayIncludes
*
* @returns 如果在数组中找到了 `value`,则返回 true。否则返回 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>
Source
贡献者
Anthony Fu
丶远方
Anthony Fu
变更日志
v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
0a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.0
on 3/14/2023