Skip to content
On this page

useSum

Category
Export Size
270 B
Package
@vueuse/math
Last Changed
2 months ago

Get the sum of an array reactively

Usage

import { useSum } from '@vueuse/math'

const array = ref([1, 2, 3, 4])
const sum = useSum(array) // Ref<10>
import { useSum } from '@vueuse/math'

const array = ref([1, 2, 3, 4])
const sum = useSum(array) // Ref<10>
import { useSum } from '@vueuse/math'

const a = ref(1)
const b = ref(3)

const sum = useSum(a, b, 2) // Ref<6>
import { useSum } from '@vueuse/math'

const a = ref(1)
const b = ref(3)

const sum = useSum(a, b, 2) // Ref<6>

Type Declarations

export declare function useSum(
  array: MaybeComputedRef<MaybeComputedRef<number>[]>
): ComputedRef<number>
export declare function useSum(
  ...args: MaybeComputedRef<number>[]
): ComputedRef<number>
export declare function useSum(
  array: MaybeComputedRef<MaybeComputedRef<number>[]>
): ComputedRef<number>
export declare function useSum(
  ...args: MaybeComputedRef<number>[]
): ComputedRef<number>

Source

SourceDocs

Contributors

Changelog

v8.9.3 on 7/14/2022
bf059 - feat: support rest usage
4d887 - feat: new function (#1837)

Released under the MIT License.