Home  >  Article  >  WeChat Applet  >  How to use UUID in applet

How to use UUID in applet

王林
王林forward
2021-02-05 08:26:564933browse

How to use UUID in applet

Just introduce and use it directly in the mini program like other packages.

Tips:

If the mini program does not support third-party packages, you need to write your own method to export.

This method is available for personal testing. The format of the generated uuid is:

 7b611f1e-6a5f-4501-b658-27295f275066

Create file—_uuid.js

const uuid = function () {
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";
 
  var uuid = s.join("");
  return uuid
}

// 需要导出
module.exports = {
    uuid
}

Use:

// 引入
// 使用相对路径引入创建的文件
const util = require(&#39;../utils/_uuid.js&#39;);

// 使用时直接使用即可
getUUid() {
    const uuid = util.uuid();
    // 可打印值看看
    // `7b611f1e-6a5f-4501-b658-27295f275066`
}

Related recommendations: Mini Program Development Tutorial

The above is the detailed content of How to use UUID in applet. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete