vue 使用 qrcodejs2 生成二维码

vue 使用 qrcodejs2 生成二维码

安装 npm install qrcodejs2 --save

<template>
  <body>
    <div id="qqq">
      <div id="qrCode" ref="qrCodeDiv"></div>
    </div>
  </body>
</template>

<script>
import QRCode from "qrcodejs2";
export default {
  name: "qrCode",

  data() {
    return {
      src2: "https://s1.ax1x.com/2022/05/07/OMGDGd.png",
    };
  },
  mounted: function () {
    this.$nextTick(function () {
      this.bindQRCode();
    });
  },
  methods: {
    bindQRCode: function () {
      new QRCode(this.$refs.qrCodeDiv, {
        text: "http:www.baidu.com",
        width: 200,
        height: 200,
        colorDark: "#333333", //二维码颜色
        colorLight: "#ffffff", //二维码背景色
        render: "canvas",
        sec: "https://z3.ax1x.com/2021/04/08/cJz0G4.jpg",
        correctLevel: QRCode.CorrectLevel.L, //容错率,L/M/H
      });
    },
  },
};
</script>

<style lang='less'>
#qqq {
  background-color: #111;
  width: 300px;
  height: 300px;
  margin: 0 auto; /*水平居中*/
  position: relative;
}

#qrCode {
  display: inline-block;
  margin: 14px auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-100px, -100px);

  img {
    width: 200px;
    height: 200px;
    background-color: #fff; //设置白色背景色
    padding: 6px; // 利用padding的特性,挤出白边
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vue1024

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值