代码之家  ›  专栏  ›  技术社区  ›  Paul

创建二维码组件并将其转换为base64图像

  •  0
  • Paul  · 技术社区  · 6 年前

    在一张桌子里( react-data-table-component ),我有元素,这些元素之一,文字必须转换成二维码。

    我正在尝试各种模块( qrcode.react, react-google-qrcode, etc.

    问题是它们是组件,因此将它们用作文档的唯一方法是:

    <qrCode value = "text" />
    

    因为我必须把它放在一个pdf文件中,我必须生成。

    所以我想我用base64编码了这个图像。

    但我找不到办法。

    0 回复  |  直到 6 年前
        1
  •  0
  •   Berkay Bindebir    6 年前

    你可以用 https://www.npmjs.com/package/qrcode

        QRCode.toDataURL(<YOUR_DATASET>, {type: "png"})
        .then(img => {
           // Then you can do whatever you want with this img
        })
    
    推荐文章