js生成二维码 qrcode
js生成二维码
1.安装qrcode
//在项目文件夹中执行:
npm install --save qrcode
//或者,将其全局安装以使用qrcode命令行来保存qrcode图像或生成可在终端中查看的图像。
npm install -g qrcode
2.用法
- CLI
Usage: qrcode [options] <input string> QR Code options:
-v, --version QR Code symbol version (1 - 40)
-e, --error Error correction level [choices: "L", "M", "Q", "H"]
-m, --mask Mask pattern (0 - 7) Renderer options:
-t, --type Output type [choices: "png", "svg", "utf8"]
-w, --width Image width (px)
-s, --scale Scale factor
-q, --qzone Quiet zone size
-l, --lightcolor Light RGBA hex color
-d, --darkcolor Dark RGBA hex color Options:
-o, --output Output file
-h, --help Show help [boolean] Examples:
qrcode "some text" Draw in terminal window
qrcode -o out.png "some text" Save as png image
qrcode -d F00 -o out.png "some text" Use red as foreground color
- 模块使用
<!-- index.html -->
<html>
<body>
<canvas id="canvas"></canvas>
<script src="bundle.js"></script>
</body>
</html> // index.js -> bundle.js
var QRCode = require('qrcode')
var canvas = document.getElementById('canvas') QRCode.toCanvas(canvas, 'sample text', function (error) {
if (error) console.error(error)
console.log('success!');
})
- nodejs使用
var QRCode = require('qrcode')
QRCode.toDataURL('I am a pony!', function (err, url) {
console.log(url)
})
- es6/es7
//可以使用Promises和Async / Await来代替回调函数。 import QRCode from 'qrcode' // With promises
QRCode.toDataURL('I am a pony!')
.then(url => {
console.log(url)
})
.catch(err => {
console.error(err)
}) // With async/await
const generateQR = async text => {
try {
console.log(await QRCode.toDataURL(text))
} catch (err) {
console.error(err)
}
}
js生成二维码 qrcode的更多相关文章
- 使用JS生成二维码QRCode
这其实很简单,项目中使用插件即可生成,主要有两种方式: 一种是在项目中使用java生成,把图片生成到某个目录,然后在用tomcat或者nginx虚拟一下路径即可访问,这种方式我们不用,因为会在目录中生 ...
- QRCode.js生成二维码
QRCode的GitHub地址: https://github.com/KeeeX/qrcodejs 该版本解决了主版本(https://github.com/davidshimjs/qrcodejs ...
- 使用jquery.qrcode.js生成二维码
通常生成二维码的方式有两种:第一种是java代码的形式,第二种是通过Js方式. 在这里我做个记录,用js生成二维码,可以在官网下载源码:http://jeromeetienne.github.io/j ...
- js生成二维码的jquery组件–qrcode
js生成二维码的jquery组件–qrcode 2015/01/30 / 2508 VIEWS / JAVASCRIPT, JQUERY 有一些耗cpu的计算,完全可以在客户端上计算,比如生成二维码. ...
- qrcode.js生成二维码因字符串过长而报错
前端使用qrcode.js生成二维码的时候.有时候是会出现 qrcode length overflow (1632>1056) 目前使用的有效的解决办法是重新下载新版的qrcode.js 下载 ...
- js生成二维码以及点击下载二维码
js生成二维码 jquery.qrcode.js可以快速使用页面生成二维码.但改项目有两个小问题:1.不支持中文:2.不支持二维码中间生成图片. 支持中文的jquery-qrcode jquery.q ...
- php--------使用js生成二维码
php生成二维码有多种方式,可以在JS中,也可以使用php库,今天写的这个小案例是使用JS生成二维码. 其他方式可以看下一篇文章:php--------php库生成二维码和有logo的二维码 网站开发 ...
- Java与JS生成二维码
1.二维码概念 二维码/二维条码是用某种特定的集合图形按一定规律在平面上(二维方向上)分布的黑白相间的图形记录数据符号信息的图片. 黑线是二进制的1,空白的地方是二进制的0,通过1.0这种数据组合用于 ...
- js 生成二维码图片
1.用纯JavaScript实现的微信二维码图片生成器 QRCode.js是javascript实现二维码(QRCode)制作生成库. QRCode.js有着良好的跨浏览器兼容性(高版本使用HTML5 ...
随机推荐
- github文件上传与下载
一.文件上传 ①.注册并登陆github,进入Github首页,点击New repository新建一个项目. ②.填写相应信息后点击create即可 Repository name: 仓库名称 De ...
- mysql知识点汇总
1. 数据库的安装 2. 数据库设计需要注意什么 3. SQL语句优化 4. 怎样处理慢查询? 5. 怎样更好的利用数据库索引? 6. 事务隔离级别有哪些?怎么实现的? 7. 数据库锁有哪些? 8. ...
- webservice常用两种身份验证方式
在项目开发,我们经常会使用WebService,但在使用WebService时我们经常会考虑以下问题:怎么防止别人访问我的WebService?从哪里引用我的WebService?对于第一个问题,就涉 ...
- coredump文件抓取设置
ulimit -c unlimitedecho 1 > /proc/sys/kernel/core_uses_pidecho "/tmp/core-%e-%s-%u-%g-%p-%t& ...
- hashlib hmac configparser subprocess xlrd xlwt
hashlib模块:加密 import hashlib # 基本使用 cipher = hashlib.md5('需要加密的数据的二进制形式'.encode('utf-8')) print(ciphe ...
- ajax基本用法介绍
使用ajax需要同时在模板中引用jQuery,ajax基本使用方法如下: $.ajax({ url:'url', type:'POST', data:{'k1':v1,'k2':v2,}, dataT ...
- pytest使用简介
pytest是基于py unittest的一个单元测试框架,用起来比unittest简单不少,不过和unittest使用不太一样,总结如下: 格式: case的py文件名必须是test开头 def用例 ...
- linux清理缓存的命令
查看缓存的命令 free -m 清理缓存的命令 echo 1 > /proc/sys/vm/drop_caches echo 2 > /proc/sys/vm/drop_caches e ...
- 论文笔记:SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks
SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks 2019-04-02 12:44:36 Paper:ht ...
- strcmp()字符串比较函数用法
函数原型: int strcmp(const char *s1, const char *s2); 头文件: #include <string.h> 功能: 用来比较两个字符串 参数: s ...