在Vue项目中使用 qrcodejs2 生成二维码

安装

yarn add qrcodejs2

引入

import QRCode from "qrcodejs2";

使用

组件中

<div ref="'qrcode"></div>

方法中

showQrcode() {
    
    
    	 /** correctLevel 容错级别:
          *(1)QRCode.CorrectLevel.L 
          *(2)QRCode.CorrectLevel.M 
          *(3)QRCode.CorrectLevel.Q 
          *(4)QRCode.CorrectLevel.H
          **/
      let opts = {
    
    
        correctLevel: QRCode.CorrectLevel.H,
        type: "image/png", //生成的二维码类型
        quality: 0.3, //二维码质量
        margin: 12, //二维码留白边距
        width: 200, //宽
        height: 180, //高
        text: "TEXT", //二维码内容
        color: {
    
    
          dark: "#333333", //前景色
          light: "#fff", //背景色
        },
      };
      let msg = this.$refs["qrcode"];
      new QRCode(msg, opts);
    },

加油,奥里给!~

猜你喜欢

转载自blog.csdn.net/qq_39007178/article/details/111592175