当前位置: 首页 > news >正文

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

完整示例:

<template><view><view class="titleBar">执法检查“通行码”信息</view><view class="twoCode"><canvas canvas-id="qrcode"></canvas></view></view>
</template><script>import UQrcode from '@/pages/common/uqrcode.js'export default {onLoad() {this.QRurl = 'https://mp.csdn.net'this.qrFun(this.QRurl)},data() {return {qrcodeData: '', // 存储二维码图片的 Base64 编码QRurl: '',qrWidth: 0}},created() {// this.getCode()},mounted() {// this.generateQRCode('https://www.example.com'); // 生成二维码},methods: {qrFun: function(text) {UQrcode.make({canvasId: 'qrcode', //切记canvasId 里边的内容需要跟canvas里边canvas-id="qrcode"的名字一样componentInstance: this, // 当前页面的this,需要传递过去text: text, //需要转成二维码的内容是后端传过来的,我这里是onLoad传过来的,根                              据自己的需要size: 200, // // 二维码的大小,单位是pxmargin: 0, // 二维码的边距,如果设置为0就无边距backgroundColor: '#ffffff', // 二维码的背景色foregroundColor: '#000000', // 二维码的前景色,即二维码图案的颜色fileType: 'jpg', // 生成的二维码图片格式errorCorrectLevel: UQrcode.errorCorrectLevel.H, // 二维码的错误纠正级别,H为最高级别// 成功生成二维码的回调函数success: res => {// 在这里可以获取生成的二维码图片}})}},}
</script><style lang="scss">page {background-color: #eaf0f6;padding-top: 20px;}.titleBar {width: 90%;height: 50px;line-height: 50px;margin-top: 50px;background-image: url("../static/images/gra-linear.png");background-size: 100% 50px;margin: 0 auto;border: 1px solid #C1D6E6;text-align: center;font-size: 25px;}.twoCode {width: 90%;height: 300px;// line-height: 50px;border: 1px solid #C1D6E6;margin: 0 auto;display: flex;align-items: center;/* 画布上下居中 */justify-content: center;/* 画布左右居中 */background-color: #fff;}/* 画布样式 */.twoCode canvas {width: 200px;height: 200px;// background-color: red;}.topBar {height: 50px;width: 100%;background-image: url("../static/images/header-bg.png");background-repeat: repeat-x;display: flex;align-items: center;/* 上下居中 */justify-content: center;/* 左右居中 */}.topBar img {margin-top: 5px;height: 40px;width: auto;}</style>

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

http://www.lryc.cn/news/169091.html

相关文章:

  • 深度解剖数据在栈中的应用
  • Android10 SystemUI系列 需求定制(一)状态栏控制中心默认tile定制属性适配
  • 【微信小程序】文章设置
  • 程序员在线周刊(冒泡算法篇)
  • string
  • html的日期选择插件
  • OPPO哲库事件 “ 始末 ” ! 集体打哑谜?
  • 数据聚类分析
  • 前 40 个 Microsoft Excel 面试问题答案
  • ros2学习笔记:shell环境变量脚本setup.bash[-z][-n][-f]参数作用
  • xss渗透(跨站脚本攻击)
  • 9参数化重采样时频变换,基于MATLAB平台,程序已调通,可直接替换数据进行分析。
  • RK3568平台开发系列讲解(调试篇)系统运行相关频率设置
  • 嵌入式:驱动开发 Day2
  • RK3399平台开发系列讲解(入门篇)VIM的基础命令
  • Rocky Linux 安装图解(替代centos)服务器+桌面
  • webpack 基础配置
  • C语言和mfc按格式读取文件数据
  • SQLyog 各版本下载与安装(目前最新版本为13.2.0)
  • CopyOnWrite 容器
  • 云服务部署:AWS、Azure和GCP比较
  • Linux安装Ansible管理工具
  • 七天学会C语言-第二天(数据结构)
  • 高级功能的PID控制器在电离规等真空计线性化处理中的应用
  • 元素全排列问题的新思路(DFS,递归,计数器)
  • 机器学习 day35(决策树)
  • 小程序引入vant-Weapp保姆级教程及安装过程的问题解决
  • LeetCode 周赛上分之旅 #45 精妙的 O(lgn) 扫描算法与树上 DP 问题
  • JavaScript-DOM实战案例
  • STM32 学习笔记1:STM32简介