Skip to content

useArrayJoin

Category
Export Size
137 B
Last Changed
15 minutes ago

响应式 Array.join

用法

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

js
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]

与响应式数组一起使用

js
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,

与响应式分隔符一起使用

js
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]

类型声明

typescript
/**
 * 响应式 `Array.join`
 *
 * @see https://vueuse.org/useArrayJoin
 * @param list - 被调用的数组。
 * @param separator - 用于分隔数组中每对相邻元素的字符串。如果省略,则使用逗号(",")分隔数组元素。
 *
 * @returns 包含所有数组元素连接的字符串。如果 arr.length 为 0,则返回空字符串。
 */
export declare function useArrayJoin(
  list: MaybeRefOrGetter<MaybeRefOrGetter<any>[]>,
  separator?: MaybeRefOrGetter<string>,
): ComputedRef<string>

Source

SourceDocs

贡献者

Anthony Fu
丶远方
Levi (Nguyễn Lương Huy)
Anthony Fu
Levi (Nguyễn Lương Huy)

变更日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
0a72b - feat(toValue): rename resolveUnref to toValue

Released under the MIT License.