溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Angular.JS如何生成動(dòng)態(tài)二維碼

發(fā)布時(shí)間:2021-06-24 11:33:43 來(lái)源:億速云 閱讀:232 作者:小新 欄目:web開(kāi)發(fā)

這篇文章主要介紹Angular.JS如何生成動(dòng)態(tài)二維碼,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

一、場(chǎng)景

二維碼的場(chǎng)景,很多。這里是二維碼一種小場(chǎng)景,比如分享一個(gè)鏈接,商品鏈接,項(xiàng)目鏈接,優(yōu)惠券鏈接…

技術(shù)實(shí)現(xiàn),如果用后端實(shí)現(xiàn),需要構(gòu)造輸出一個(gè)圖片流。或者后端生產(chǎn)二維碼圖片,給圖片地址就好了。弊端,這個(gè)二維碼就是一個(gè)鏈接,后端的文件 IO 操作,還得考慮存儲(chǔ)。太費(fèi)力。

如果前端實(shí)現(xiàn),這樣就很輕松了。這只是個(gè)分享二維碼,分享出去給人家掃一掃。利用前端的 canvas,這里坐下調(diào)研。

jq 封裝的 qrcode.js ,文章網(wǎng)上一大堆。

angular js :https://github.com/monospaced/angular-qrcode

二、使用

1.安裝 angular-qrcode

git clone https://github.com/monospaced/angular-qrcode.git

cd angular-qrcode
npm install

2.引入 js 文件

<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 配置中加入對(duì)這個(gè)模塊的依賴:

angular
.module('your-module', [
'monospaced.qrcode',
]);

3.使用

在線案例:monospaced.github.io/angular-qrcode

使用元素:

<qrcode data="string"></qrcode>

具體配置參數(shù):

<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 互斥,不能同時(shí)使用。具體參數(shù)入下:

<qrcode version="{{version}}" error-correction-level="{{level}}" size="{{size}}" data="{{var}}" href="{{var}}" rel="external nofollow" color="{{color}}" background="{{background}}" download></qrcode>

以上是“Angular.JS如何生成動(dòng)態(tài)二維碼”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI