Skip to content

useToNumber

类别
导出体积
213 B
上次更改
2 months ago

将字符串 ref 转换为数字。

使用方法

ts
import { 
useToNumber
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
str
=
shallowRef
('123')
const
number
=
useToNumber
(
str
)
number
.
value
// 123

类型声明

ts
export interface UseToNumberOptions {
  /**
   * 用于将值转换为数字的方法。
   *
   * Or a custom function for the conversion.
   *
   * @default 'parseFloat'
   */
  
method
?: "parseFloat" | "parseInt" | ((
value
: string | number) => number)
/** * 传递给 `parseInt` 的数学数字系统的基数。 * 仅适用于 `method: 'parseInt'` */
radix
?: number
/** * 将 NaN 替换为零 * * @default false */
nanToZero
?: boolean
} /** * 将字符串 ref 转换为数字。 * * @__NO_SIDE_EFFECTS__ */ export declare function
useToNumber
(
value
:
MaybeRefOrGetter
<number | string>,
options
?: UseToNumberOptions,
):
ComputedRef
<number>

源码

源码文档

贡献者

一纸忘忧
Anthony Fu
Anthony Fu
IlyaL
SerKo
btea
_Ghosteye

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
635bb - feat: method support custom function (#4441)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)