vue移動app掃碼功能


第一步:

  

  上面這段代碼寫在index.html里面,我也不知道為什么,可能是全局的關系;

第二步:

  

  定義一個按鈕,點擊啟動掃碼功能,另外再定義一個盒子來當做掃碼的容器;我給這個盒子定義了一個id類名:bcid

 

第三步: 第三步代碼多,直接粘貼,方便你我他,我也是在別人手上抄過來,作了部分改變

    

//創建掃描控件
startRecognize1() {
document.getElementById('bcid').style.display = 'block';
document.getElementsByClassName('scanCode')[0].style.display = 'none';
let that = this;
if (!window.plus) return;
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked;
setTimeout(function(){
that.startScan1();
},100)

function onmarked(type, result, file) {
switch (type) {
case plus.barcode.QR:
type = 'QR';
break;
case plus.barcode.EAN13:
type = 'EAN13';
break;
case plus.barcode.EAN8:
type = 'EAN8';
break;
default:
type = '其它' + type;
break;
}
result = result.replace(/\n/g, '');
that.codeUrl = result;
alert(that.codeUrl);
if(that.codeUrl){
that.cancelScan1();
that.closeScan1();
}
}
},
//開始掃描
startScan1() {
if (!window.plus) return;
scan.start();
},
//關閉掃描
cancelScan1() {
if (!window.plus) return;
scan.cancel();
},
//關閉條碼識別控件
closeScan1() {
document.getElementById('bcid').style.display = 'none';
document.getElementsByClassName('scanCode')[0].style.display = 'block';
if (!window.plus) return;
scan.close();
},

————————————————————————————————————————————————————————————————————————————————————————————

 

 

  

 

 

 

 

 

 

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM