记录js生成barcode,qrcode

server/2024/10/22 15:41:25/

1、barcode条形码

引入第三方JsBarcode.all.min.js,地址https://github.com/lindell/JsBarcode

可以下载到本地 下载地址

<script  src="/static/JsBarcode.all.min.js"></script>

或者cdn

<script  src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.0/dist/JsBarcode.all.min.js"></script>

或者npm

javascript">npm install jsbarcode --save

在使用页面

<canvas id="barcode"></canvas>
<!-- or -->
<img id="barcode"/>
<!-- or -->
<svg id="barcode"></svg>

js中

javascript">JsBarcode('#barcodeId', this.barCodeForm.value, {width: this.barCodeForm.width || 2,height: this.barCodeForm.height || 50,fontSize: this.barCodeForm.fontSize || 14,background: null// 透明背景});
// 获取生成的节点信息let image = document.getElementById("barcodeId");console.dir(image)

2、生成二维码 qrcode

引入第三方qrcode.min.js,地址https://github.com/soldair/node-qrcode

下载到本地,下载地址

<script  src="/static/qrcode.min.js"></script>

或者npm 

javascript">npm install --save qrcode或者npm install -g qrcode

 在使用页面中

<canvas id="qrCodeId"></canvas>
<!--or-->
<img id="qrCodeId"/>

在js中

javascript">let opts = {errorCorrectionLevel: 'H',type: 'image/png',width: this.QRCodeForm.width || 60,height: this.QRCodeForm.height || 60,quality: 0.5,//取值范围为0.1到1.0,数值越小,二维码质量越高,图片文件也越大。margin: this.QRCodeForm.margin || 1,color: {dark: '#000000ff', // 二维码的颜色,加上alpha通道实现透明light: '#00000000' // 背景透明}};// 使用img时QRCode.toDataURL(this.QRCodeForm.value, opts, function (err, url) {if (err) throw err;let image = document.getElementById('qrCodeId');image.src = url;console.dir(image)
})
// 使用canvas时
var canvas = document.getElementById('qrCodeId')
QRCode.toCanvas(canvas, 'sample text', function (error) {if (error) console.error(error)console.log('success!');
})


http://www.ppmy.cn/server/110278.html

相关文章

蓝桥等级考1级c++组真题(选择)第一套(含答案解析)

纯个人整理&#xff0c;如有错误欢迎指正 1.以下关于C程序描述错误的一项是&#xff08;&#xff09; A.完整的程序必须有且仅有一个主函数&#xff0c;主函数的名字为main B.程序可以调用库函数&#xff0c;但必须要包含相对应的头文件 C.程序可以有注释行&#xff0c;注释行会…

云首席产品规划专家的必修课

大家好&#xff0c;我是卢旗。 今天和大家探讨一下云计算规划专家的必备研究内容。 一、市场与客户需求分析&#xff1a; 1&#xff0c;市场调研&#xff1a;深入了解当前及未来云计算市场的趋势、竞争格局、客户需求变化等&#xff0c;识别出潜在的市场机会和威胁。 结合20…

计算机毕业设计选题推荐-传统文化网站-Java/Python项目实战

✨作者主页&#xff1a;IT研究室✨ 个人简介&#xff1a;曾从事计算机专业培训教学&#xff0c;擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。 ☑文末获取源码☑ 精彩专栏推荐⬇⬇⬇ Java项目 Python…

linux安装milvus数据库lite版本

https://milvus.io/docs/milvus_lite.md 参考上述教程&#xff0c;直接安装该包即可。标准版和分布式版要运行docker。 pip install -U pymilvus 下面是官方的demo&#xff0c;一起看看 from pymilvus import MilvusClient # 导入库&#xff0c;客户端 import numpy as np # …

Golang 开发使用 gorm 时打印 SQL 语句

目录 1. 使用 Debug 方法2. 全局设置日志级别3. 自定义 Logger4. 总结 参考 gorm 文档&#xff1a;https://gorm.io/zh_CN/docs/logger.html Gorm 有一个 默认 logger 实现&#xff0c;默认情况下&#xff0c;它会打印慢 SQL 和错误。如果想要全部或部分打印 SQL 的话可以通过设…

小柴带你学AutoSar系列三、标准和规范篇(3)ModeManagement

目录 ModeManagementGuide 2 Overall mechanisms and concepts 2.1 Declaration of modes 2.2 Mode managers and mode users 2.3 Modes in the RTE 2.4 Modes in the Basic Software Scheduler 2.5 Communication of modes 3 Configuration of the Basic Software Mod…

我如何解决 java.lang.ClassNotFoundException:javax.xml.bind.DatatypeConverter

优质博文&#xff1a;IT-BLOG-CN 问题 我如何解决java.lang.ClassNotFoundException&#xff1a;javax.xml.bind.DatatypeConverter 2024-08-25T02:31:25.46202:00 ERROR 21868 --- [fintonic-oauth] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet…

入行「游戏策划」,该从何处下手?

想知道策划岗位该怎么入行可点击蓝链 相比较起以技术为最重要评判标准的开发岗&#xff0c; 「游戏策划」这一岗位在非业界人士的眼中 一直都是一个风评方差很大的岗位。 有人说策划岗又轻松又威风&#xff0c; 只需要输出想法&#xff0c;落地都交给开发&#xff0c; 干…