Vue Barcode and QR Code Scanner

1.0.3 · abandoned · verified Sun Apr 19

This library provides Vue.js components, `StreamBarcodeReader` and `ImageBarcodeReader`, enabling barcode and QR code scanning within web applications. It leverages the ZXing ("zebra crossing") image processing library for its core decoding capabilities, supporting various 1D and 2D formats from either a live video camera feed or uploaded image files. The current latest version, 1.0.3, was published approximately three years ago, with Vue 3 compatibility introduced in version 1.0.0. For applications requiring Vue 2 support, users must install version 0.0.3. While the package offers straightforward integration, community forks like `@teckel/vue-barcode-reader` describe this original package as abandoned, suggesting a lack of active maintenance and potential for unaddressed issues or performance improvements found in alternatives. TypeScript definitions are available via `@types/vue-barcode-reader` for better developer experience.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up both `StreamBarcodeReader` for live camera scanning and `ImageBarcodeReader` for image file scanning within a Vue 3 component. It includes handlers for successful decodes, camera loading, and error states, displaying the last decoded value.

import { defineComponent } from 'vue';
import { StreamBarcodeReader, ImageBarcodeReader } from 'vue-barcode-reader';

export default defineComponent({
  components: {
    StreamBarcodeReader,
    ImageBarcodeReader,
  },
  data() {
    return {
      decodedText: '',
      cameraLoaded: false,
      streamError: null as string | null,
      imageError: null as string | null
    };
  },
  methods: {
    onDecode(result: string) {
      console.log('Decoded text:', result);
      this.decodedText = result;
    },
    onLoaded() {
      console.log('StreamBarcodeReader camera loaded!');
      this.cameraLoaded = true;
    },
    onStreamError(error: Error) {
      console.error('StreamBarcodeReader error:', error);
      this.streamError = error.message;
    },
    onImageError(error: Error) {
      console.error('ImageBarcodeReader error:', error);
      this.imageError = error.message;
    },
  },
});

/* In your template: */
/*
<template>
  <div>
    <h1>Vue Barcode Reader Demo</h1>
    
    <h2>Live Camera Scan</h2>
    <StreamBarcodeReader
      @decode="onDecode"
      @loaded="onLoaded"
      @error="onStreamError"
    ></StreamBarcodeReader>
    <p v-if="!cameraLoaded">Loading camera...</p>
    <p v-if="streamError" style="color: red;">Camera Error: {{ streamError }}</p>

    <h2>Scan from Image</h2>
    <ImageBarcodeReader
      @decode="onDecode"
      @error="onImageError"
    ></ImageBarcodeReader>
    <p v-if="imageError" style="color: red;">Image Scan Error: {{ imageError }}</p>

    <h3 v-if="decodedText">Last Decoded: {{ decodedText }}</h3>
  </div>
</template>
*/

view raw JSON →