Skip to content

getUuid 生成随机标识

function getUuid(): string

生成一个随机字符串标识。浏览器环境优先使用 Web Crypto API 生成随机数,不支持时回退到 Math.random()

参数

该函数不需要传入参数。

返回值

返回值说明类型
uuid基于 36 进制表示的随机字符串string

示例

typescript
import { getUuid } from '@mingto/tools'

const id = getUuid()
// 例如:'k9x3ab'

const domId = `item-${getUuid()}`

注意事项

  • 该函数生成的是随机标识字符串,不是 RFC 4122 标准 UUID。