uniapp在h5頁(yè)面實(shí)現(xiàn)掃碼功能(html5-qrcode)
發(fā)布時(shí)間:2024-06-11 17:05:18 作者:Yui_NIE
我要評(píng)論
這篇文章主要介紹了uniapp在h5頁(yè)面實(shí)現(xiàn)掃碼功能(html5-qrcode),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
安裝
npm install html5-qrcode
代碼
<template>
<view class="container">
<button class="scan" @click="scanCode">打開(kāi)相機(jī)掃碼</button>
<view class="reader-box" v-if="isScaning">
<view class="reader" id="reader"></view>
</view>
</view>
</template>
<script>
import {
Html5Qrcode
} from 'html5-qrcode';
export default {
data() {
return {
html5Qrcode: null,
isScaning: false,
}
},
methods: {
startScan() {
this.isScaning = true;
Html5Qrcode.getCameras().then(devices => {
if (devices && devices.length) {
this.html5Qrcode = new Html5Qrcode('reader');
this.html5Qrcode.start({
facingMode: 'environment',
}, {
fps: 24,
qrbox: 280
}, (decodeText, decodeResult) => {
console.log(decodeText)
if (decodeText) {
this.stopScan();
this.isScaning = false;
}
}, (err) => {
console.log(err)
});
}
});
},
stopScan() {
this.html5Qrcode.stop();
},
scanCode() {
console.log('helo')
this.startScan();
}
}
}
</script>
<style scoped>
.container{
height:100%;
}
.reader-box {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.5);
}
.reader {
width: 540rpx;
height: 540rpx;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>測(cè)試效果
uniapp運(yùn)行到瀏覽器


到此這篇關(guān)于uniapp在h5頁(yè)面實(shí)現(xiàn)掃碼功能(html5-qrcode)的文章就介紹到這了,更多相關(guān)html5 qrcode掃碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章

使用 html5-qrcode實(shí)現(xiàn)掃碼功能
html5-qrcode是輕量級(jí)和跨平臺(tái)的QR碼和條形碼掃碼的JS庫(kù),集成二維碼、條形碼和其他一些類(lèi)型的代碼掃描功能,這篇文章主要介紹了使用 html5-qrcode 掃碼功能,需要的朋友可2023-09-13uniapp+Html5端實(shí)現(xiàn)PC端適配
這篇文章主要介紹了uniapp+Html5端實(shí)現(xiàn)PC端適配,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)2020-07-15


