index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <van-dialog class="app-qrcode" v-model:show="showDialog" confirm-button-text="取消">
  3. <div class="app-qrcode__container" ref="qrcodeRef">
  4. <img src="@mobile/assets/logo.png" />
  5. </div>
  6. </van-dialog>
  7. </template>
  8. <script lang="ts" setup>
  9. import { shallowRef, computed, watch, nextTick } from 'vue'
  10. import { Dialog } from 'vant'
  11. import QRCode from 'qrcodejs2'
  12. const props = defineProps({
  13. show: {
  14. type: Boolean,
  15. default: false
  16. },
  17. content: String
  18. })
  19. const VanDialog = Dialog.Component
  20. const emit = defineEmits(['update:show'])
  21. const qrcodeRef = shallowRef<HTMLDivElement>()
  22. const showDialog = computed({
  23. get: () => props.show,
  24. set: (val) => emit('update:show', val)
  25. })
  26. watch(showDialog, (status) => {
  27. if (status) {
  28. nextTick(() => {
  29. const el = qrcodeRef.value
  30. if (el) {
  31. el.innerHTML = ''
  32. new QRCode(el, {
  33. width: 180,
  34. height: 180,
  35. text: props.content
  36. })
  37. }
  38. })
  39. }
  40. })
  41. </script>
  42. <style lang="less">
  43. @import './index.less';
  44. </style>