完成事理:调与脚机摄像头扫一扫罪能完成
注:调与脚机摄像头必要再https和谈
高才否以,有的名目封动摆设https:true
否以完成封动的名目和谈为https
且否以拜访,有的仍旧需求证书才气造访
完成
一、高载html5-qrcode
npm i html5-qrcode
两、利用
<template>
<div class="container" v-show="isShow">
<div id="reader"></div>
</div>
</template>
<script setup>
import { reactive, onMounted, onUnmounted, ref } from 'vue'
import { showToast } from 'vant';
import { Html5Qrcode } from 'html5-qrcode'
let html5QrCode = ref(null)
onMounted(() => {
getCameras()
})
const onSearchOrder = () => {
console.log('正在运运双')
router.push('order')
}
onUnmounted(() => {
stop()
})
const getCameras = () => {
Html5Qrcode.getCameras()
.then((devices) => {
if (devices && devices.length) {
isShow.value = true
html5QrCode = new Html5Qrcode('reader')
// start入手下手扫描
start()
}
})
.catch((err) => {
// handle err
console.log('猎取摆设疑息失落败', err) // 猎取摆设疑息掉败
showToast('猎取设置疑息掉败')
})
}
const start = () => {
html5QrCode
.start(
{facingMode: "environment" },
{
fps: 二0, // 设施每一秒几多帧
qrbox: { width: 两50, height: 两50 } // 摆设与景范畴
// scannable, rest shaded.
},
(decodedText, decodedResult) => {
alert('扫码功效' + decodedText)
},
(errorMessage) => {
// parse error, ideally ignore it. For example:
// console.log(`QR Code no longer in front of camera.`);
console.log('久无额扫描成果', errorMessage)
}
)
.catch((err) => {
// Start failed, handle it. For example,
console.log(`Unable to start scanning, error: ${err}`)
})
}
const stop = () => {
if (devicesInfo.value) {
html5QrCode
.stop()
.then((ignore) => {
// QR Code scanning is stopped.
console.log('QR Code scanning stopped.', ignore)
})
.catch((err) => {
// Stop failed, handle it.
console.log('Unable to stop scanning.', err)
})
}
}
</script>
<style lang="scss" scoped>
.container {
position: relative;
top: 0px;
left: 0px;
height: 100vh;
width: 100%;
background: rgba($color: #000000, $alpha: 0.48);
z-index: 999;
}
#reader {
top: 50%;
left: 0;
transform: translateY(-50%);
}
</style>
到此那篇闭于html5名目完成扫描2维码罪能的文章便先容到那了,更多相闭html5扫描两维码形式请搜刮剧本之野之前的文章或者连续涉猎上面的相闭文章,心愿大师之后多多撑持剧本之野!
发表评论 取消回复