当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 【uuid】- 唯一标识

【uuid】- 唯一标识

2020年01月03日  | 移动技术网IT编程  | 我要评论

2020-01-02

uuid ,universally unique identifier ,通用唯一标识符。

 

//定义一个生成 uuid 的方法
const getuuid = () => { const s = [] // 定义一个十六进制字符串 const hexdigits = '0123456789abcdef' for (let i = 0; i < 36; i++) { // 0x10 是十六进制数,转化为十进制为16 s[i] = hexdigits.substr(math.floor(math.random() * 0x10), 1) } // bits 12-15 of the time_hi_and_version field to 0010 s[14] = '4' // bits 6-7 of the clock_seq_hi_and_reserved to 01 // 0x3为3 , 0x8为8 s[19] = hexdigits.substr((s[19] && 0x3) || 0x8, 1) s[8] = s[13] = s[18] = s[23] = '-' const uuid = s.join('') return uuid } export default getuuid

// 使用时直接调用 getuuid() 即可

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网