qrcode.vue 943 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="qrcode">
  3. <image class="image" v-if="img" :src="img" :style="{width: sizeSync + 'px', height: sizeSync + 'px'}" />
  4. </view>
  5. </template>
  6. <script>
  7. import QR from './qrcode.js';
  8. export default {
  9. name: 'number-box',
  10. props: {
  11. val: {
  12. type: String,
  13. default: ''
  14. },
  15. size: {
  16. type: Number,
  17. default: 100
  18. }
  19. },
  20. data() {
  21. return {
  22. img: '',
  23. sizeSync: 100
  24. }
  25. },
  26. methods: {
  27. creatQrcode() {
  28. let val = this.val + '';
  29. if (!val) {
  30. return;
  31. }
  32. let img = QR.createQrCodeImg(val, {
  33. size: parseInt(this.size)
  34. });
  35. this.img = img;
  36. },
  37. clearQrcode() {
  38. this.img = '';
  39. }
  40. },
  41. watch: {
  42. size(newVal, oldVal) {
  43. if (newVal != oldVal) {
  44. this.sizeSync = newVal;
  45. this.creatQrcode();
  46. }
  47. }
  48. },
  49. created() {
  50. this.sizeSync = this.size;
  51. }
  52. }
  53. </script>
  54. <style>
  55. .qrcode {
  56. display: flex;
  57. justify-content: center;
  58. }
  59. </style>