QR コード arale-qrcode を生成 | 一時アドレスを BLOB に変換 | キャンバスを画像に変換 | BLOB をファイルに変換

インストール

npm i arale-qrcode

引用

import AraleQRCode from 'arale-qrcode'

作成する

createERWEIMA() {
    
    
	let qrcode = new AraleQRCode({
    
    
        "render": "png",  // 生成的类型 'svg' or 'table'
        "text": '我是二维码的内容', // 需要生成二维码的链接
        "size": 160 // 生成二维码大小
      });
      // this.$refs.qrcode.appendChild(qrcode)
      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 をファイルに変換する

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

おすすめ

転載: blog.csdn.net/weixin_46211267/article/details/131206381
おすすめ