蔡cai
蔡cai
  • 发布:2024-07-11 11:32
  • 更新:2024-07-11 11:32
  • 阅读:69

【解决】使用yz-qr生成二维码,canvas有时候会空白问题

分类:uni-app
// 在weapp-qrcode.js里  

// 注释下面这个代码  
// _oContext.draw()  

// 添加下面这些代码  
setTimeout(() => {  
    _oContext.draw(true, (canvasResult) => {  
        console.log('二维码绘画成功', canvasResult);  
        this.success && this.success();  
    });  
})
// 在yz-qr.vue文件下添加success成功回调  
new qrCode('canvas', {  
    text: "123456",  
    width: 100,  
    height: 100,  
    ......  
    success: () => {  
        // 二维码绘画成功回调  
        uni.canvasToTempFilePath({  
            canvasId: this.canvasId,  
            success: (res) => {  
                this.canvasQrPath = res.tempFilePath  
                this.$emit('update:qrPath', this.canvasQrPath)  
                console.log('canvas转成图片成功:', res.tempFilePath);  
            },  
            fail: (err) => {  
                console.log('canvas转成图片失败:', err)  
            }  
        }, this)  
    }  
})

↓↓↓ 各位大佬点点赞

0 关注 分享

要回复文章请先登录注册