qrcodejs2二維碼

    //組件中使用
        // 1.引入:
           import QRCode from 'qrcodejs2'
        //2.html結(jié)構(gòu)
           <div id="qrcode" ref="qrcode"></div>
        //3.方法
            qrcode(){
                let qrcode = new QRCode('qrcode', {
                width: 100,
                height: 100, // 高度
                text:sessionStorage.getItem('text'), // 二維碼內(nèi)容
                render: 'canvas',   // 設(shè)置渲染方式(有兩種方式 table和canvas,默認(rèn)是canvas)
               // background: '#f0f',
               // foreground: '#ff0'
             });
          },
       //4.調(diào)用
        //下載
           //html
             <a id="downloadImg"></a>
             <button class="button" @click="downloadImg" title="下載">下載</button>
           //方法
            downloadImg(){
          var img = document.getElementById('qrcode').getElementsByTagName('img')[0];
       // 構(gòu)建畫布
          var canvas = document.createElement('canvas');
          canvas.width = img.width;
          canvas.height = img.height;
          canvas.getContext('2d').drawImage(img, 0, 0);
      // 構(gòu)造url
          var url = canvas.toDataURL('image/png');
          document.getElementById('downloadImg').setAttribute('href', url);
          document.getElementById('downloadImg').setAttribute('download', '郵箱+推薦二維碼.jpg');
          document.getElementById('downloadImg').click();
        }

把要下載的圖片生成流的形式進(jìn)行下載

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容