创建一个二维码图像然后转换为base64

Create a qrcode image then convert to base64

我正在使用 http://davidshimjs.github.io/qrcodejs/ 生成二维码

          var qrcode = new QRCode("qrcode", {
            text: "http://jindo.dev.naver.com/collie",
            width: 128,
            height: 128,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
          });
          console.log(qrcode);
          console.log(qrcode._el.children[1].currentSrc);

我可以在“二维码”中找到base64编码
但是为什么当我 运行:

时我会变空
console.log(qrcode._el.children[1].currentSrc);

有没有其他方法获取base64码?

尝试:

setTimeout(function () {
    const base64String = document.querySelector("#qrcode img").src;
});

原因是它只是异步运行,需要一些时间来设置图像属性。