跳到主要内容

useArrayJoin

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

响应式的 Array.join

用法

与多个 ref 组成的数组一起使用

ts
import { 
useArrayJoin
} from '@vueuse/core'
const
item1
=
ref
('foo')
const
item2
=
ref
(0)
const
item3
=
ref
({
prop
: 'val' })
const
list
= [
item1
,
item2
,
item3
]
const
result
=
useArrayJoin
(
list
)
// result.value: foo,0,[object Object]
item1
.
value
= 'bar'
// result.value: bar,0,[object Object]

与响应式数组一起使用

ts
import { 
useArrayJoin
} from '@vueuse/core'
const
list
=
ref
(['string', 0, {
prop
: 'val' }, false, [1], [[2]], null,
undefined
, []])
const
result
=
useArrayJoin
(
list
)
// result.value: string,0,[object Object],false,1,2,,,
list
.
value
.
push
(true)
// result.value: string,0,[object Object],false,1,2,,,,true
list
.
value
= [null, 'string',
undefined
]
// result.value: ,string,

与响应式分隔符一起使用

ts
import { 
useArrayJoin
} from '@vueuse/core'
const
list
=
ref
(['string', 0, {
prop
: 'val' }])
const
separator
=
ref
()
const
result
=
useArrayJoin
(
list
,
separator
)
// result.value: string,0,[object Object]
separator
.
value
= ''
// result.value: string0[object Object]
separator
.
value
= '--'
// result.value: string--0--[object Object]

类型声明

ts
export type 
UseArrayJoinReturn
=
ComputedRef
<string>
/** * Reactive `Array.join` * * @see https://vueuse.org.cn/useArrayJoin * @param list - the array was called upon. * @param separator - a string to separate each pair of adjacent elements of the array. If omitted, the array elements are separated with a comma (","). * * @returns a string with all array elements joined. If arr.length is 0, the empty string is returned. * * @__NO_SIDE_EFFECTS__ */ export declare function
useArrayJoin
(
list
:
MaybeRefOrGetter
<
MaybeRefOrGetter
<any>[]>,
separator
?:
MaybeRefOrGetter
<string>,
):
UseArrayJoinReturn

来源

源码文档

贡献者

Anthony Fu
Anthony Fu
SerKo
Levi (Nguyễn Lương Huy)
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 许可证发布。