【uuid】- 唯一标识

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() 即可
 

猜你喜欢

转载自www.cnblogs.com/fengwenya/p/12141917.html