vue生成二维码

1、下载依赖的文件

    npm install qrcodejs2 --S

2、引入文件

     import QRCode from 'qrcodejs2';

3、设置盛放二维码的容器

<article class="qrcode" ref="fixed_qrcode"></article>

4、初始化二维码参数

mounted(){
    let than=this;
    than.$nextTick(function(){
        than.qrCoupon=new QRCode(than.$refs.fixed_qrcode,{
            text:' ',
            width:256, // 图像宽
            height:256, // 高
            typeNumber:4,
            colorDark:'#000', // 前景色
            colorLight:'#fff', //背景色
            correctLevel:QRCode.CorrectLevel.L //容错级别(L/M/Q/H)
        });
    });
  }

5、设置二维码内容

methods(){
   showQrCoupon(){            
 this.qrCoupon.makeCode('www.baidu.com'); 
    },
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容