vue使用QRCode实现生成二维码

<template>
  <canvas ref="qrcode"></canvas>
</template>

<script>
import QRCode from 'qrcode'

export default {
  props: {
    url: {
      type: String,
      default() {
        return ''
      },
    },
  },
  mounted() {
    this.creatQrCode()
  },
  methods: {
    creatQrCode() {
      if (this.url) {
        QRCode.toCanvas(this.$refs.qrcode, this.url, {
          width: 154,
          height: 154,
        })
      }
    },
  },
}
</script>

 

posted @ 2021-08-16 15:39  放飞的回忆  阅读(126)  评论(0)    收藏  举报