文档
API

BarcodeScanner

NameTypeDefault ValueDescription
optionsScanOptionsDEFAULT_OPTIONS/
onCapture(barcodes: DetectedBarcode[]) => any/当检测到指定类型的码时触发
trackConstraintsMediaTrackConstraintsDEFAULT_CONSTRAINTS基于MediaTrackConstraints (opens in a new tab)标准

useCamera

NameTypeDefault ValueDescription
refRefObject<HTMLVideoElement>Required*HTMLVideoElement实例
trackConstraintsMediaTrackConstraintsDEFAULT_CONSTRAINTS基于MediaTrackConstraints (opens in a new tab)标准

DEFAULT_CONSTRAINTS

{
  width: { min: 640, ideal: 1280 },
  height: { min: 480, ideal: 720 },
  facingMode: {
    ideal: 'environment'
  },
  advanced: [
    { width: 1920, height: 1280 },
    { aspectRatio: 1.333 }
  ]
}

useScanning

NameTypeDefault ValueDescription
refRefObject<HTMLVideoElement>Required*HTMLVideoElement实例
optionsScanOptionsDEFAULT_OPTIONSdelay: 扫描间隔
formats: 扫描的条码格式, 支持格式

DEFAULT_OPTIONS

{
  delay: 1000,
  formats: ['qr_code']
}

useTorch

NameTypeDefault ValueDescription
openBooleanfalse是否默认启用闪光灯

useStreamState

管理通过useCamera获取到的stream

function useStreamState (): [MediaStream | undefined, (newState: MediaStream) => void]

Types

ScanOptions

interface ScanOptions {
  delay?: number
  formats?: string[]
}