How to use UUID in applet

王林
Release: 2021-02-28 15:40:15
forward
4966 people have browsed it

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
Copy after login

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
}
Copy after login

Use:

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

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

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template