replaceAll is not a funtion

replaceAll is not a funtion

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, "_")
  );
}

上一篇:nexus搭建即入门使用001


下一篇:vue - 使用jquery