子组件中使用weapp-qrcode生成二维码

 
import { ref, watch, nextTick, getCurrentInstance } from 'vue'
import QRCodeLib from '@/utils/weapp.qrcode.esm.js'
或者使用npm下载,注意子组件中需要加instance
import QRCodeLib from "weapp-qrcode";
const instance = getCurrentInstance()
 
QRCodeLib({
            width: 200,
            height: 200,
            canvasId: 'qrcode',
            ctx: uni.createCanvasContext('qrcode', instance),
            text: encryptedStr,
            success: (res) => {
                console.log('✅ 二维码绘制成功', res)
            },
            fail: (err) => {
                console.log('❌ 绘制失败:', err)
            }
        })
 
 
posted @ 2026-05-28 15:29  世界险恶你要内心强大  阅读(2)  评论(0)    收藏  举报