//定义一个生成 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() 即可
如对本文有疑问, 点击进行留言回复!!
vue源码实战render.js与$nextTick的异步调用
网友评论