1. 安装QRCode

npm install --save qrcodejs qrcodejs2

2.使用页面引入QRCode

import QRCode from 'qrcodejs2'

3. new一个QRCode并使用

var qrcode = new QRCode(qrcodeObj, {
        text: encodeURI(url),
        width: 130,
        height: 130
      });

4.案列

<template>
  <div>
    <div class="qrcode-outbox">
      <div ref="qrcode" style="width:100%;height:100%;"></div>
    </div>
  </div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {
  data() {
    return {};
  },
  mounted() {
      this.creatQrcode('https://www.baidu.com/')
  },
  methods: {
    // 生成二维码
    creatQrcode(url) {
      let qrcodeObj = this.$refs.qrcode;
      $(qrcodeObj).html("");
      var qrcode = new QRCode(qrcodeObj, {
        text: encodeURI(url),
        width: 130,
        height: 130
      });
    }
  }
};
</script>
<style>
.qrcode-outbox {
  position: relative;
  width: 150px;
  height: 150px;
  border: 1px solid #9eabb8;
  padding: 10px;
  background-color: #fff;
  box-sizing: border-box;
}
</style>

 

相关文章:

  • 2022-12-23
  • 2021-08-31
  • 2021-10-30
  • 2021-10-18
  • 2022-12-23
  • 2021-11-24
  • 2021-07-28
  • 2021-08-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案