A Vue 2 barcode/QR scanner based on https://github.com/olefirenko/vue-barcode-reader
npm install vue-barcode-qrcode-scannersh
npm install vue-barcode-qrcode-scanner --save
`
Or
`sh
yarn add vue-barcode-qrcode-scanner
`
Usage
The Vue Barcode and QR code scanner works out of the box by just including it.
$3
Once a stream from the users camera is loaded, it is displayed and continuously scanned for barcodes. Results are indicated by the scan event.
`js
import { CameraCodeScanner } from "vue-barcode-qrcode-scanner";
`
In your template you can use this syntax:
`html
`
When the Video Camera loads, it emits a load event that exposes all the available
options inside the ZXing BrowserMultiFormatReader API.
`js
methods: {
onLoad({
controls,
scannerElement,
browserMultiFormatReader
}) {
console.log(controls)
// ---- BrowserMultiFormatReader Controls API ----
// {
// stop: f() // Stops the video stream (Basically turns off the camera)
// }
console.log(scannerElement)
// ---- The ref to the video native element that streams the video-camera output ----
//
console.log(browserMultiFormatReader)
// ---- A reference to the BrowserMultiFormatReader object. ----
// hints: Map(0)
// options: {
// delayBetweenScanAttempts: 500
// delayBetweenScanSuccess: 500
// tryPlayVideoTimeout: 5000
// }
// reader: MultiFormatReader
// Please refer to the ZXing (Zebra crossing) browser documentation
},
onScan({ result, raw }) {
console.log(result)
// ---- Scan result ----
// "http://en.m.wikipedia.org"
console.log(raw)
// ---- Raw BrowserMultiFormatReader.decodeFromVideoDevice result ----
// format: 11
// numBits: 272
// rawBytes: Uint8Array(34) [65, 150, 135, 71, 71, 3, 162, 242, 246, 86, 226, 230, 210, 231, 118, 150, 182, 151, 6, 86, 70, 150, 18, 230, 247, 38, 112, 236, 17, 236, 17, 236, 17, 236, buffer: ArrayBuffer(34), byteLength: 34, byteOffset: 0, length: 34, Symbol(Symbol.toStringTag): 'Uint8Array']
// resultMetadata: Map(2) {2 => Array(1), 3 => 'Q'}
// resultPoints: (4) [FinderPattern, FinderPattern, FinderPattern, AlignmentPattern]
// text: "http://en.m.wikipedia.org"
// timestamp: 1654535879486
}
}
`
Fixes
1. According to Issue 33 in ZXing Browser I are supposed to use ZXing Browser's BrowserMultiFormatReader in the Browser Layer and not ZXing-JS Library.
ZXing Browser provides an intuitive API to
scan anything and is currently being maintained and actively improved upon.
However using ZXing Library for the Browser Layer is deprecated.
This change also fixes the "Trying to play video that is already playing." warning.
2. Issue 19 in vue-barcode-reader states that even though the video component has been destroyed the camera is still on. This is due to beforeUnmount option not existing prior to Vue 3.2.7.
I are using beforeDestroy instead for Vue 2 support.
3. vue-barcode-reader isn't minified by default and contributions aren't easy make due to the absence of development scripts, so I compiled the library with vue-sfc-rollup and Vue CLI
How to contribute
Feel free to submit issues and enhancement requests, however if you want
to contribute just follow these steps:
1. Fork this repo on GitHub
2. Clone the project to your own machine
3. Just run:
`sh
npm init
npm run serve
`
Or
`sh
yarn
yarn serve
`
and commit whatever changes you want to make.
At the end run
`sh
npm run build
`
Or
`sh
yarn build
``