vue项目引用QRCode生成二维码


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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM