js生成唯一标识uid
推荐使用uuid库
GitHub: uuidjs
// 生成唯一id
//推荐使用uuid库 npm install uuid link:https://github.com/uuidjs/uuid
import { v4 as uuidv4 } from 'uuid';
const uid = uuidv4()
//以下方式不保险
export const createUid = ()=> {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}