Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useToNumber.md
1---2category: Utilities3---45# useToNumber67Reactively convert a string ref to number.89## Usage1011```ts12import { useToNumber } from '@vueuse/core'13import { shallowRef } from 'vue'1415const str = shallowRef('123')16const number = useToNumber(str)1718number.value // 12319```2021## Type Declarations2223```ts24export interface UseToNumberOptions {25/**26* Method to use to convert the value to a number.27*28* Or a custom function for the conversion.29*30* @default 'parseFloat'31*/32method?: "parseFloat" | "parseInt" | ((value: string | number) => number)33/**34* The base in mathematical numeral systems passed to `parseInt`.35* Only works with `method: 'parseInt'`36*/37radix?: number38/**39* Replace NaN with zero40*41* @default false42*/43nanToZero?: boolean44}45/**46* Reactively convert a string ref to number.47*48* @__NO_SIDE_EFFECTS__49*/50export declare function useToNumber(51value: MaybeRefOrGetter<number | string>,52options?: UseToNumberOptions,53): ComputedRef<number>54```55