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>

 

posted on 2020-06-28 15:09  活在当下zql  阅读(3617)  评论(0)    收藏  举报