• 【RuoYi移动端】uni-app中实现生成二维码功能(代码示例)


    完整示例:

    1. <template>
    2. <view>
    3. <view class="titleBar">
    4. 执法检查“通行码”信息
    5. </view>
    6. <view class="twoCode">
    7. <canvas canvas-id="qrcode"></canvas>
    8. </view>
    9. </view>
    10. </template>
    11. <script>
    12. import UQrcode from '@/pages/common/uqrcode.js'
    13. export default {
    14. onLoad() {
    15. this.QRurl = 'https://mp.csdn.net'
    16. this.qrFun(this.QRurl)
    17. },
    18. data() {
    19. return {
    20. qrcodeData: '', // 存储二维码图片的 Base64 编码
    21. QRurl: '',
    22. qrWidth: 0
    23. }
    24. },
    25. created() {
    26. // this.getCode()
    27. },
    28. mounted() {
    29. // this.generateQRCode('https://www.example.com'); // 生成二维码
    30. },
    31. methods: {
    32. qrFun: function(text) {
    33. UQrcode.make({
    34. canvasId: 'qrcode', //切记canvasId 里边的内容需要跟canvas里边canvas-id="qrcode"的名字一样
    35. componentInstance: this, // 当前页面的this,需要传递过去
    36. text: text, //需要转成二维码的内容是后端传过来的,我这里是onLoad传过来的,根 据自己的需要
    37. size: 200, // // 二维码的大小,单位是px
    38. margin: 0, // 二维码的边距,如果设置为0就无边距
    39. backgroundColor: '#ffffff', // 二维码的背景色
    40. foregroundColor: '#000000', // 二维码的前景色,即二维码图案的颜色
    41. fileType: 'jpg', // 生成的二维码图片格式
    42. errorCorrectLevel: UQrcode.errorCorrectLevel.H, // 二维码的错误纠正级别,H为最高级别
    43. // 成功生成二维码的回调函数
    44. success: res => {
    45. // 在这里可以获取生成的二维码图片
    46. }
    47. })
    48. }
    49. },
    50. }
    51. </script>
    52. <style lang="scss">
    53. page {
    54. background-color: #eaf0f6;
    55. padding-top: 20px;
    56. }
    57. .titleBar {
    58. width: 90%;
    59. height: 50px;
    60. line-height: 50px;
    61. margin-top: 50px;
    62. background-image: url("../static/images/gra-linear.png");
    63. background-size: 100% 50px;
    64. margin: 0 auto;
    65. border: 1px solid #C1D6E6;
    66. text-align: center;
    67. font-size: 25px;
    68. }
    69. .twoCode {
    70. width: 90%;
    71. height: 300px;
    72. // line-height: 50px;
    73. border: 1px solid #C1D6E6;
    74. margin: 0 auto;
    75. display: flex;
    76. align-items: center;
    77. /* 画布上下居中 */
    78. justify-content: center;
    79. /* 画布左右居中 */
    80. background-color: #fff;
    81. }
    82. /* 画布样式 */
    83. .twoCode canvas {
    84. width: 200px;
    85. height: 200px;
    86. // background-color: red;
    87. }
    88. .topBar {
    89. height: 50px;
    90. width: 100%;
    91. background-image: url("../static/images/header-bg.png");
    92. background-repeat: repeat-x;
    93. display: flex;
    94. align-items: center;
    95. /* 上下居中 */
    96. justify-content: center;
    97. /* 左右居中 */
    98. }
    99. .topBar img {
    100. margin-top: 5px;
    101. height: 40px;
    102. width: auto;
    103. }
    104. </style>

    记得在@/pages/common/uqrcode.js文件夹下放入uqrode.js文件,请到网上下载。

  • 相关阅读:
    白话强化学习(理论+代码)
    用移位距离和标定神经网络迭代次数
    Hive3 单机版(含Derby 多用户及Spark on Hive)
    动态代理IP怎么设置?动态代理IP有哪些应用场景?
    PX4模块设计之十八:Logger模块
    【制作100个unity游戏之27】使用unity复刻经典游戏《植物大战僵尸》,制作属于自己的植物大战僵尸随机版和杂交版12(附带项目源码)
    Linux环境配置安装Redis
    Python基础知识
    Linux 中设置静态IP的方法步骤
    小车联网—通过ESP8266将速度发送到客户端
  • 原文地址:https://blog.csdn.net/dxnn520/article/details/132795917