欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

html5項(xiàng)目實(shí)現(xiàn)掃描二維碼功能

  發(fā)布時(shí)間:2023-10-07 16:25:11   作者:浮橋   我要評(píng)論
掃描二維碼是很常見(jiàn)的一種功能,本文就來(lái)介紹一下html5項(xiàng)目實(shí)現(xiàn)掃描二維碼功能,具有一定的參考價(jià)值,感興趣的可以了解一下

實(shí)現(xiàn)原理:調(diào)取手機(jī)攝像頭掃一掃功能實(shí)現(xiàn)
注:調(diào)取手機(jī)攝像頭需要再https協(xié)議下才可以,有的項(xiàng)目啟動(dòng)配置https:true可以實(shí)現(xiàn)啟動(dòng)的項(xiàng)目協(xié)議為https且可以訪(fǎng)問(wèn),有的還是需要證書(shū)才能訪(fǎng)問(wèn)

實(shí)現(xiàn)

1、下載html5-qrcode

npm i html5-qrcode

2、使用

<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('在運(yùn)運(yùn)單')
    router.push('order')
}
onUnmounted(() => {
    stop()
})
const getCameras = () => {
    Html5Qrcode.getCameras()
        .then((devices) => {
            if (devices && devices.length) {
                isShow.value = true
                html5QrCode = new Html5Qrcode('reader')
                // start開(kāi)始掃描
                start()
            }
        })
        .catch((err) => {
            // handle err
            console.log('獲取設(shè)備信息失敗', err) // 獲取設(shè)備信息失敗
            showToast('獲取設(shè)備信息失敗')
        })
}
const start = () => {
    html5QrCode
        .start(
            {facingMode: "environment" },
            {
                fps: 20, // 設(shè)置每秒多少幀
                qrbox: { width: 250, height: 250 } // 設(shè)置取景范圍
                // scannable, rest shaded.
            },
            (decodedText, decodedResult) => {
            	alert('掃碼結(jié)果' + decodedText)
            },
            (errorMessage) => {
                // parse error, ideally ignore it. For example:
                // console.log(`QR Code no longer in front of camera.`);
                console.log('暫無(wú)額掃描結(jié)果', 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>

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

相關(guān)文章

最新評(píng)論