跳到主要内容

useArrayFindLast

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

响应式的 Array.findLast

用法

ts
import { 
useArrayFindLast
} from '@vueuse/core'
const
list
= [
ref
(1),
ref
(-1),
ref
(2)]
const
positive
=
useArrayFindLast
(
list
,
val
=>
val
> 0)
// positive.value: 2

与响应式数组一起使用

ts
import { 
useArrayFindLast
} from '@vueuse/core'
const
list
=
reactive
([-1, -2])
const
positive
=
useArrayFindLast
(
list
,
val
=>
val
> 0)
// positive.value: undefined
list
.
push
(10)
// positive.value: 10
list
.
push
(5)
// positive.value: 5

类型声明

ts
export type 
UseArrayFindLastReturn
<
T
= any> =
ComputedRef
<
T
| undefined>
/** * Reactive `Array.findLast` * * @see https://vueuse.org.cn/useArrayFindLast * @param list - the array was called upon. * @param fn - a function to test each element. * * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned. * * @__NO_SIDE_EFFECTS__ */ export declare function
useArrayFindLast
<
T
>(
list
:
MaybeRefOrGetter
<
MaybeRefOrGetter
<
T
>[]>,
fn
: (
element
:
T
,
index
: number,
array
:
MaybeRefOrGetter
<
T
>[]) => boolean,
):
UseArrayFindLastReturn
<
T
>

来源

源码文档

贡献者

Anthony Fu
Anthony Fu
SerKo
Robin
IlyaL
Levi (Nguyễn Lương Huy)

更新日志

v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v13.1.0
c1d6e - feat(shared): 确保返回类型存在 (#4659)
v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.3.0
59f75 - feat(toValue): 废弃 @vueuse/shared 中的 toValue,转而使用 Vue 的原生函数
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。