前提
由于涉及到调用手机摄像头,涉及到隐私,必须在HTTPS环境使用。
重点说明
在手机端使用,PC端使用会报错获取信息失败。
一、下载插件
下载html5-qrcode插件
yarn add html5-qrcode
或
npm i html5-qrcode
二、使用demo
<template>
<div class="container">
<div id="reader"></div>
</div>
<button @click="getCameras">扫码</button>
<span>{
{
result }}</span>
</template>
<script setup>
import {
onMounted, ref, onUnmounted } from 'vue'
import {
Html5Qrcode } from 'html5-qrcode'
import {
showToast } from 'vant';
const cameraId = ref('')
const devicesInfo = ref('')
const html5QrCode = ref(