QCode.vue 650 B

123456789101112131415161718192021222324252627
  1. <script setup lang="ts">
  2. // eslint-disable-next-line ts/ban-ts-comment
  3. // @ts-expect-error
  4. import UQRCode from 'uqrcodejs'
  5. const props = defineProps<{ text: string, qwidth: number }>()
  6. const _this = getCurrentInstance()
  7. function createQRCode() {
  8. const qr = new UQRCode()
  9. qr.data = props.text
  10. qr.size = props.qwidth || 100
  11. qr.make()
  12. const canvasContext = uni.createCanvasContext('qrcode', _this)
  13. qr.canvasContext = canvasContext
  14. qr.drawCanvas()
  15. }
  16. createQRCode()
  17. </script>
  18. <template>
  19. <canvas id="qrcode" canvas-id="qrcode" :style="{ width: `${props.qwidth}px`, height: `${props.qwidth}px` }" />
  20. </template>
  21. <style scoped>
  22. </style>