生活随笔
收集整理的這篇文章主要介紹了
前端页面实现扫码
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
業(yè)務(wù)場(chǎng)景:H5中用到掃碼的場(chǎng)景,常見掃碼簽到、掃碼簽退
框架:vue
依賴:npm i html5-qrcode
<template
><div
><div
class="fx_qrcode"><div id
="reader" width
="600px"></div
></div
></div
>
</template
><script
>
import { Html5Qrcode
} from 'html5-qrcode';export default {data() {return {};},mounted() {this.getCameras();},methods: {getCameras() {Html5Qrcode
.getCameras().then(devices => {if (devices
&& devices
.length
) {if (devices
.length
> 1) {this.cameraId
= devices
[1].id
;} else {this.cameraId
= devices
[0].id
;}this.devices
= devices
;this.start();}}).catch(err => {});},start() {const self
= this;this.html5QrCode
= new Html5Qrcode('reader');this.html5QrCode
.start(this.cameraId
,{fps: 10, qrbox: { width: 250, height: 250 }, },(decodedText, decodedResult) => {this.handleRequest(decodedText
);},errorMessage => {},).catch(err => {});},stop() {this.html5QrCode
.stop().then(ignore => {}).catch(err => {});},async handleRequest(decodedText) {},},
};
</script
><style
>
.fx_qrcode
{margin
-top
: 200px
;
}
</style
>
總結(jié)
以上是生活随笔為你收集整理的前端页面实现扫码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。