vue3生成二维码,在dialog中显示

用npm安装

npm install qrcode --save-dev

引用

import QRCode from "qrcode";

在vue中编写

<canvas id="QRCode_header" style="width: 150px; height: 150px"></canvas>

在dialog中增加@open="openOrder"方法

methods: {

getQRCode() {
                //生成的二维码为URL地址js
                this.qrUrl = this.creForm;
                let opts = {
                    errorCorrectionLevel: "H", //容错级别
                    type: "image/png", //生成的二维码类型
                    quality: 0.3, //二维码质量
                    margin: 0, //二维码留白边距
                    width: 150, //宽
                    height: 150, //高
                    text: this.creForm.orderId, //二维码内容
                    color: {
                        dark: "#333333", //前景色
                        light: "#fff", //背景色
                    },
                };
                            
                let msg = document.getElementById("QRCode_header");
                // 将获取到的数据(val)画到msg(canvas)上
                QRCode.toCanvas(msg, this.qrUrl, opts, function(error) {
                    if (error) {
                        console.log("二维码加载失败", error);
                        this.$message.error("二维码加载失败");
                    }
                });
            },
openOrder() {
                this.$nextTick(() => {
                    this.getQRCode();
                })
            },
      },

然后正常打开dialog就可以啦

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值