源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Angular JS 生成动态二维码的方法

  • 时间:2022-09-07 11:42 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Angular JS 生成动态二维码的方法
[b]一、场景[/b] 二维码的场景,很多。这里是二维码一种小场景,比如分享一个链接,商品链接,项目链接,优惠券链接… 技术实现,如果用后端实现,需要构造输出一个图片流。或者后端生产二维码图片,给图片地址就好了。弊端,这个二维码就是一个链接,后端的文件 IO 操作,还得考虑存储。太费力。 如果前端实现,这样就很轻松了。这只是个分享二维码,分享出去给人家扫一扫。利用前端的 canvas,这里坐下调研。 jq 封装的 qrcode.js ,文章网上一大堆。 angular js :[url=https://github.com/monospaced/angular-qrcode]https://github.com/monospaced/angular-qrcode[/url] [b]二、使用[/b] [b]1.安装 angular-qrcode[/b] git clone [url=https://github.com/monospaced/angular-qrcode.git]https://github.com/monospaced/angular-qrcode.git[/url]
cd angular-qrcode
npm install
[b]2.引入 js 文件[/b]
<script src="/node_modules/qrcode-generator/js/qrcode.js"></script>
<script src="/node_modules/qrcode-generator/js/qrcode_UTF8.js"></script>
<script src="/node_modules/angular-qrcode/angular-qrcode.js"></script>
并在你 angular 配置中加入对这个模块的依赖:
angular
.module('your-module', [
'monospaced.qrcode',
]);
[b]3.使用[/b] 在线案例:monospaced.github.io/angular-qrcode 使用元素:
<qrcode data="string"></qrcode>
具体配置参数:
<qrcode data="string" version="2" error-correction-level="Q" size="200" color="#fff" ba kground="#000"></qrcode>
作为可下载的图片:
<qrcode data="string" download></qrcode>
作为有链接的二维码:
<qrcode data="http://example.com" href="http://example.com" rel="external nofollow" ></qrcode> 
download 和 href 互斥,不能同时使用。具体参数入下:
<qrcode version="{{version}}" error-correction-level="{{level}}" size="{{size}}" data="{{var}}" href="{{var}}" rel="external nofollow" color="{{color}}" background="{{background}}" download></qrcode>
以上所述是小编给大家介绍的Angular JS 生成动态二维码的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部