0
点赞
收藏
分享

微信扫一扫

replaceAll is not a funtion

迪莉娅1979 2022-01-26 阅读 38
javascript

在这里插入图片描述

function randomSessionId() {
  let ua = new Uint8Array(20);
  new DataView(ua.buffer).setUint32(0, Math.floor(+new Date() / 1000));
  let crypto = window.crypto || window.msCrypto;
  if (crypto) {
    crypto.getRandomValues(ua.subarray(4, 20));
  }
  return (
    "1." +
    transformUint8ArrayToBase64(ua)
      .replaceAll("+", "-")
      .replaceAll("/", "_")
  );
}

解决方法为:

function randomSessionId() {
  let ua = new Uint8Array(20);
  new DataView(ua.buffer).setUint32(0, Math.floor(+new Date() / 1000));
  let crypto = window.crypto || window.msCrypto;
  if (crypto) {
    crypto.getRandomValues(ua.subarray(4, 20));
  }
  return (
    "1." +
    transformUint8ArrayToBase64(ua)
      .replace(/\+/g, "-")
      .replace(/\//g, "_")
  );
}

举报

相关推荐

0 条评论