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