生成二维码插件

非 Y 不嫁゛ 提交于 2020-01-20 01:00:27

在components里放入qrcode.vue
qrcode.vue:

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

<script>
import QRCode from "qrcodejs2";
export default {
  name: "qrCode",
  props: ["url"],
  data() {
    return {};
  },
  mounted: function() {
    this.$nextTick(function() {
      this.bindQRCode();
    });
  },
  methods: {
    bindQRCode: function() {
      new QRCode(this.$refs.qrCodeDiv, {
        text: this.url,
        width: 200,
        height: 200,
        colorDark: "#333333", //二维码颜色
        colorLight: "#ffffff", //二维码背景色
        correctLevel: QRCode.CorrectLevel.L //容错率,L/M/H
      });
    }
  }
};
</script>

使用插件
html:

 <!-- 二维码 -->
    <el-dialog title="二维码" :visible.sync="dialogVisible" width="30%">
      <span style="display:flex;justify-content: center;">
        <qr :url="url"></qr>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>

js:

import qr from "../../components/qrcode";
  components: {
    qr
  },
 // 二维码按钮
    twocode(row) {
      console.log(row);
      this.dialogVisible = true;
      this.url = `http://192.168.1.118:8081/oneregister?maid=${row.maid}`;
      console.log(this.url);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!