Vue input content/link to generate QR code

Method 1: qrcode (no icon icon)

npm i qrcodejs2 --save
   
   
    
    

full code


   
   
    
    
  1. <template >
  2. <div class = "flex-box" >
  3. <div > qrcode (no icon icon) < /div >
  4. < div class = "qr-code" ref = "qrCodeUrl" > < / div >
  5. < / div >
  6. < /template >
  7. <script >
  8. import QRCode from 'qrcodejs2';
  9. export default {
  10. that a() {
  11. return {};
  12. },
  13. methods: {
  14. / * Create QR code * /
  15. creatQrCode() {
  16. new QRCode(this.$refs.qrCodeUrl, {
  17. text: 'https://blog.csdn.net/AdminGuan', / / QR code content
  18. width: 150,
  19. height: 150 ,
  20. colorDark: '#000',
  21. colorLight: '#fff',
  22. correctLevel: QRCode.CorrectLevel.H
  23. });
  24. }
  25. },
  26. mounted() {
  27. this.creatQrCode(); / / create QR code
  28. }
  29. };
  30. < /script >
  31. <style scoped >
  32. .flex-box {
  33. display: flex;
  34. align-items: center;
  35. justify-content: center;
  36. flex-direction: column;
  37. }
  38. .qr-code {
  39. padding: 10px;
  40. margin-top: 20px;
  41. background-color: #fff;
  42. border: 1px solid red;
  43. }
  44. < /style >

Method 2: vue- qr (with icon icon)

Official website address: vue-qr-npm

npm install vue-qr --save
   
   
    
    

import import method

import vueQr from 'vue-qr'; // vue2.0
   
   
    
    
import vueQr from 'vue-qr/src/packages/vue-qr.vue'; // vue3.0 (support vite)
   
   
    
    

full code


   
   
    
    
  1. <template >
  2. <div class = "flex-box" >
  3. <div > vue-qr (with icon icon) < /div >
  4. < view-qr class = "qr-code" :logoSrc = "imageUrl" :text = "qrCodeUrl" : size = "150" / >
  5. < / div >
  6. < /template >
  7. <script >
  8. import vueQr from 'view-qr' ; / / vue 2.0
  9. / / import vueQr from 'vue-qr/src/packages/vue-qr.vue' ; / / vue 3.0 (quick support)
  10. export default {
  11. components: { vueQr },
  12. that a() {
  13. return {
  14. qrCodeUrl: 'https://blog.csdn.net/AdminGuan', / / QR code content
  15. imageUrl: require( '../assets/default.jpg') / / icon path
  16. };
  17. },
  18. methods: {}
  19. };
  20. < /script >
  21. <style scoped >
  22. .flex-box {
  23. display: flex;
  24. align-items: center;
  25. justify-content: center;
  26. flex-direction: column;
  27. }
  28. .qr-code {
  29. margin-top: 20px;
  30. background-color: #fff;
  31. border: 1px solid red;
  32. }
  33. < /style >

Related Configuration Properties

attribute name meaning
text encoded content
correctLevel Tolerance level (0 - 3)
size Dimensions, same length and width, including margins
margin The outer margin of the QR code image, the default is 20px
colorDark solid color
colorLight the color of the white space
bgSrc The address of the background image to be embedded
gifBgSrc The gif address of the background image to be embedded, the normal background image will be invalid after setting. Setting this option affects performance
backgroundColor background color
backgroundDimming The color superimposed on the background image is helpful when decoding is difficult
logoSrc Logo address embedded in the center of the QR code
logoScale The value used to calculate the logo size, too large will cause decoding failure, the logo size calculation formula logoScale * (size - 2 * margin), default 0.2
logoMargin The blank border around the logo, the default is 0
logoBackgroundColor Logo background color, need to set logo margin
logoCornerRadius The fillet radius of the logo and its border, the default is 0
whiteMargin If set to true, a white border will be drawn outside the background image
dotScale Data area point reduction ratio, the default is 0.35
autoColor If true, the image will be binarized, and the default value will be used if no threshold is specified
binarizeThreshold (0 < threshold < 255) Threshold for binarization
callback The generated QR code data url can be obtained in the callback, the first parameter is the QR code data url, and the second parameter is the qid passed from props (because the QR code generation is asynchronous, so add an id for sort)
bindElement Specifies whether to automatically bind the generated QR code to HTML, the default is true

Method 1: qrcode (no icon icon)

npm i qrcodejs2 --save
   
   
  
  

full code


   
   
  
  
  1. <template >
  2. <div class = "flex-box" >
  3. <div > qrcode (no icon icon) < /div >
  4. <div class = "qr-code" ref = "qrCodeUrl" > < / div >
  5. < / div >
  6. < /template >
  7. <script >
  8. import QRCode from 'qrcodejs2';
  9. export default {
  10. that a() {
  11. return {};
  12. },
  13. methods: {
  14. / * Create QR code * /
  15. creatQrCode() {
  16. new QRCode(this.$refs.qrCodeUrl, {
  17. text: 'https://blog.csdn.net/AdminGuan', / / QR code content
  18. width: 150,
  19. height: 150 ,
  20. colorDark: '#000',
  21. colorLight: '#fff',
  22. correctLevel: QRCode.CorrectLevel.H
  23. });
  24. }
  25. },
  26. mounted() {
  27. this.creatQrCode(); / / create QR code
  28. }
  29. };
  30. < /script >
  31. <style scoped >
  32. .flex-box {
  33. display: flex;
  34. align-items: center;
  35. justify-content: center;
  36. flex-direction: column;
  37. }
  38. .qr-code {
  39. padding: 10px;
  40. margin-top: 20px;
  41. background-color: #fff;
  42. border: 1px solid red;
  43. }
  44. < /style >

Method 2: vue- qr (with icon icon)

Official website address: vue-qr-npm

npm install vue-qr --save
   
   
  
  

import import method

import vueQr from 'vue-qr'; // vue2.0
   
   
  
  
import vueQr from 'vue-qr/src/packages/vue-qr.vue'; // vue3.0 (support vite)
   
   
  
  

full code


   
   
  
  
  1. <template >
  2. <div class = "flex-box" >
  3. <div > vue-qr (with icon icon) < /div >
  4. < view-qr class = "qr-code" :logoSrc = "imageUrl" :text = "qrCodeUrl" : size = "150" / >
  5. < / div >
  6. < /template >
  7. <script >
  8. import vueQr from 'view-qr' ; / / vue 2.0
  9. / / import vueQr from 'vue-qr/src/packages/vue-qr.vue' ; / / vue 3.0 (quick support)
  10. export default {
  11. components: { vueQr },
  12. that a() {
  13. return {
  14. qrCodeUrl: 'https://blog.csdn.net/AdminGuan' , / / QR code content
  15. imageUrl: require( '../assets/default.jpg') / / icon path
  16. };
  17. },
  18. methods: {}
  19. };
  20. < /script >
  21. <style scoped >
  22. .flex-box {
  23. display: flex;
  24. align-items: center;
  25. justify-content: center;
  26. flex-direction: column;
  27. }
  28. .qr-code {
  29. margin-top: 20px;
  30. background-color: #fff;
  31. border: 1px solid red;
  32. }
  33. < /style >

Related Configuration Properties

attribute name meaning
text encoded content
correctLevel Tolerance level (0 - 3)
size Dimensions, same length and width, including margins
margin The outer margin of the QR code image, the default is 20px
colorDark solid color
colorLight the color of the white space
bgSrc The address of the background image to be embedded
gifBgSrc The gif address of the background image to be embedded, the normal background image will be invalid after setting. Setting this option affects performance
backgroundColor background color
backgroundDimming The color superimposed on the background image is helpful when decoding is difficult
logoSrc Logo address embedded in the center of the QR code
logoScale The value used to calculate the logo size, too large will cause decoding failure, the logo size calculation formula logoScale * (size - 2 * margin), default 0.2
logoMargin The blank border around the logo, the default is 0
logoBackgroundColor Logo background color, need to set logo margin
logoCornerRadius The fillet radius of the logo and its border, the default is 0
whiteMargin If set to true, a white border will be drawn outside the background image
dotScale Data area point reduction ratio, the default is 0.35
autoColor If true, the image will be binarized, and the default value will be used if no threshold is specified
binarizeThreshold (0 < threshold < 255) Threshold for binarization
callback The generated QR code data url can be obtained in the callback, the first parameter is the QR code data url, and the second parameter is the qid passed from props (because the QR code generation is asynchronous, so add an id for sort)
bindElement Specifies whether to automatically bind the generated QR code to HTML, the default is true

Guess you like

Origin blog.csdn.net/m0_71349739/article/details/131991575