qrcode.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view class="qrcode">
  3. <view class="name">
  4. <image :src="avatar" mode="" class="name-img"></image>
  5. <view class="">
  6. {{ name }}
  7. </view>
  8. </view>
  9. <view class="ma">
  10. <div class="qrCode" ref="qrCodeDiv"></div>
  11. <view class="id">
  12. <!-- {{ id }} -->
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import QRCode from 'qrcodejs2';
  19. export default {
  20. onLoad(options) {
  21. this.id = options.id
  22. console.log(this.id)
  23. this.$nextTick(function () {
  24. this.bindQRCode();
  25. })
  26. },
  27. mounted() {
  28. const data = this.$store.state.user.userInfo
  29. this.avatar = data.avatar
  30. this.name = data.nickname || data.real_name
  31. console.log(this.avatar);
  32. console.log(this.name);
  33. },
  34. data() {
  35. return {
  36. id: '',
  37. avatar: '',
  38. name: '',
  39. }
  40. },
  41. methods: {
  42. bindQRCode() {
  43. new QRCode(this.$refs.qrCodeDiv, {
  44. render : "canvas",
  45. text: this.id,
  46. width: 170,
  47. height: 170,
  48. colorDark: "#333333", //二维码颜色
  49. colorLight: "#ffffff", //二维码背景色
  50. correctLevel: QRCode.CorrectLevel.L//容错率,L/M/H
  51. })
  52. },
  53. }
  54. }
  55. </script>
  56. <style lang="scss" scoped>
  57. page {
  58. background-color: #fff;
  59. height: 100%;
  60. }
  61. .qrcode {
  62. text-align: center;
  63. .name {
  64. margin: 100rpx;
  65. image {
  66. width: 120rpx;
  67. height: 120rpx;
  68. border-radius: 50%;
  69. border: solid 1rpx #eaeaea;
  70. }
  71. }
  72. .ma {
  73. margin: 0 auto;
  74. padding: 50rpx;
  75. width: 450rpx;
  76. height: 450rpx;
  77. border: solid 1rpx #3b66f5;
  78. .name-img {
  79. width: 300rpx;
  80. height: 300rpx;
  81. }
  82. .id {
  83. font-size: 30rpx;
  84. margin: 20rpx 0;
  85. }
  86. }
  87. .about {
  88. margin: 30rpx;
  89. }
  90. }
  91. </style>