封装一个生成uuid的方法

function create_UUID(){
        var dt = new Date().getTime();
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = (dt + Math.random()*16)%16 | 0;
            dt = Math.floor(dt/16);
            return (c=='x' ? r :(r&0x3|0x8)).toString(16);
        });
        return uuid;
    }
    console.log(create_UUID());

另外可以在vue中使用uuid插件:

一、什么是 uuid ?


uuid 指 通用唯一识别码 

三、uuid 怎么在 vue 中引入并使用

安装:npm install uuid

引入:import uuid from 'uuid'

  (不过最近好像更新了 如果这样报警告用下面的)

  import v4 as uuidv4 from 'uuid'

使用:let onlyUuid = uuidv4() 

原文地址:https://www.cnblogs.com/fqh123/p/13830707.html