安装
npm i arale-qrcode
引用
import AraleQRCode from 'arale-qrcode'
创建
createERWEIMA() {
let qrcode = new AraleQRCode({
"render": "png",
"text": '我是二维码的内容',
"size": 160
});
this.cavasToImg(qrcode)
}
画布转图片
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')
},
临时地址转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 });
},
将blob转换为file
blobToFile(theBlob, fileName) {
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return new File([theBlob], fileName, { type: theBlob.type, lastModified: Date.now() });
},