You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

2 years ago
1 year ago
2 years ago
  1. <template>
  2. <div v-if="false">
  3. <!-- 你可以选择是否需要展示 base64 编码字符串 -->
  4. <div v-for="(code, index) in qrCodesBase64" :key="index">
  5. <!-- <p>{{ code }}</p>-->
  6. <img :src="code"/>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import QRCode from 'qrcode'
  12. export default {
  13. name: 'QrCode',
  14. data() {
  15. return {
  16. texts: ['text1', 'text2', 'text3'], // 你要生成二维码的文本数组
  17. qrCodesBase64: []
  18. }
  19. },
  20. methods: {
  21. init(contextList){
  22. this.texts = contextList
  23. this.generateQRCodesSync(this.texts)
  24. return this.qrCodesBase64
  25. },
  26. generateQRCodeSync(text) {
  27. let base64 = ''
  28. QRCode.toDataURL(text, { errorCorrectionLevel: 'M' }, (err, url) => {
  29. if (err) {
  30. console.error(err)
  31. return
  32. }
  33. base64 = url
  34. })
  35. return base64
  36. },
  37. generateQRCodesSync(texts) {
  38. this.qrCodesBase64 = texts.map(text => this.generateQRCodeSync(text))
  39. }
  40. },
  41. mounted() {
  42. this.generateQRCodesSync(this.texts)
  43. }
  44. }
  45. </script>
  46. <style>
  47. /* 你的样式 */
  48. </style>