Generar código QR arale-qrcode | Convertir dirección temporal en blob | Convertir lienzo en imagen | Convertir blob en archivo

Instalar

npm i arale-qrcode

cita

import AraleQRCode from 'arale-qrcode'

crear

createERWEIMA() {
    
    
	let qrcode = new AraleQRCode({
    
    
        "render": "png",  // 生成的类型 'svg' or 'table'
        "text": '我是二维码的内容', // 需要生成二维码的链接
        "size": 160 // 生成二维码大小
      });
      // this.$refs.qrcode.appendChild(qrcode)
      this.cavasToImg(qrcode)
}

Lienzo a la imagen

cavasToImg(qrcode) {
    
    
	this.fileObj.SAVE_PATH = qrcode.toDataURL("image/png")
	let blob = this.dataURLtoBlob(this.fileObj.SAVE_PATH);
	this.fileObj.file = this.blobToFile(blob, `${
      
      name}-二维码.png`);
	console.log(this.fileObj, 'file')
},

Dirección temporal a blob

dataURLtoBlob(dataurl) {
    
    
	let arr = dataurl.split(","),
	mime = arr[0].match(/:(.*?);/)[1],
	bstr = atob(arr[1]),
	n = bstr.length,
		u8arr = new Uint8Array(n);
	while (n--) {
    
    
		u8arr[n] = bstr.charCodeAt(n);
	}
	return new Blob([u8arr], {
    
     type: mime });
},

convertir blob en archivo

blobToFile(theBlob, fileName) {
    
    
	theBlob.lastModifiedDate = new Date();  // 文件最后的修改日期
	theBlob.name = fileName;                // 文件名
	return new File([theBlob], fileName, {
    
     type: theBlob.type, lastModified: Date.now() });
},

Supongo que te gusta

Origin blog.csdn.net/weixin_46211267/article/details/131206381
Recomendado
Clasificación