Skip to content

Vue

Implementation of the Qr grid library for Vue applications.

Installation

sh
npm install @qrgrid/vue
sh
bun add @qrgrid/vue
sh
pnpm install @qrgrid/vue
sh
yarn add @qrgrid/vue

Using Canvas

vue
<script>
  import { Qr } from "@qrgrid/vue/canvas";
</script>

<template>
  <Qr input="Hello World!" />
</template>

OR

vue
<script>
  import { Canvas } from "@qrgrid/vue";
</script>

<template>
  <Canvas input="Hello World!" />
</template>

Props

PropTypeDescriptionDefault
inputstringData to encode
qrOptions?QrOptionsOptions for QR encoding
image?QrImageOptionImage options for the image in QR codesizePercent: 15 opacity: 1 overlap: true border: false
size?numberCanvas size400
watchKey?string | numberKey to watch for regenerating the QR code (besides input, size,qrOptions and image).
bgColor?QrColor | ((ctx: CanvasRenderingContext2D) => QrColor)Background colorblack
color?QrColor | ((ctx: CanvasRenderingContext2D) => QrColor)QR code colorwhite
moduleStyle?ModuleStyleFunctionCustom styles for QR modules
getQrData?(qr: QR) => void;Retrieve QR data
getCanvasCtx?(ctx: CanvasRenderingContext2D) => void;Retrieve canvas context
onGenerated?(ctx: CanvasRenderingContext2D, size: number, qr: QR) => void;Callback once QR code is generated

see the props in code.

Using Svg

vue
<script>
  import { Qr } from "@qrgrid/vue/svg";
</script>

<template>
  <Qr input="Hello World!"/>
</template>

OR

vue
<script>
  import { Svg } from "@qrgrid/vue";
</script>

<template>
  <Svg input="Hello World!" />
</template>

Props

PropTypeDescriptionDefault
inputstringData to encode
qrOptions?QrOptionsQr Options for QR encoding
image?QrImageOptionImage options for image in the QR codesizePercent: 15 opacity: 1 overlap: true border: false
size?numberSVG size400
watchKey?string | numberKey to watch for regenerating the QR code (besides input, size, qrOptions and image).
bgColor?stringBackground colorblack
color?string | { codeword?: string; finder?: string }QR code colorwhite
moduleStyle?ModuleStyleFunctionCustom styles for QR modules
getQrData?(qr: QR) => void;get Qr data
onGenerated?(path: ModuleStyleFunctionParams[0], size: number, qr: QR) => void;Callback once QR code is generated

see the props in code.

Examples

Explore Styles for custom styling and other utilities

  • Basic

    vue
    <Qr input="Hello World!" />
  • ErrorCorrection

    vue
    <Qr input="Hello World!" :qrOptions="{errorCorrection: 'H'}" />
  • Color

    vue
    <Qr input="Hello World!" bgColor="#F8EDED" color="#173B45" />
  • Module Style from @qrgrid/styles

    vue
    <script>
      import { dotModuleStyle } from "@qrgrid/styles/canvas/styles";
    </script>
    
    <template>
      <Qr input="Hello World!" :moduleStyle="dotModuleStyle" />
    </template>
    vue
    <script>
      import { smoothModuleStyle } from "@qrgrid/styles/canvas/styles";
    </script>
    
    <template>
      <Qr input="Hello World!" :moduleStyle="smoothModuleStyle" />
    </template>
  • Images

    vue
    <Qr input="Hello World!" :image="{ src: './vite.svg' }" />
    vue
    <Qr input="Hello World!" :image="{ src: './vite.svg', overlap: false }" />
  • Downloading using @qrgrid/styles

    vue
    <script>
      import { Qr } from "@qrgrid/vue/canvas";
      import { downloadQr} from "@qrgrid/styles/canvas/utils";
    
      const qrRef = ref<InstanceType<typeof Qr> | null>(null);
    
      const download = () => {
        if (qrRef.value?.canvasRef) {
          downloadQr(qrRef.value?.canvasRef);
        }
      };
    </script>
    
    <template>
      <Qr input="Hello World!" ref="qrRef" />
    </template>
    vue
    <script>
      import { Qr } from "@qrgrid/vue/svg";
      import { downloadQr} from "@qrgrid/styles/svg/utils";
    
      const qrRef = ref<InstanceType<typeof Qr> | null>(null);
    
      const download = () => {
        if (qrRef.value?.svgRef) {
          downloadQr(qrRef.value?.svgRef);
        }
      };
    </script>
    
    <template>
      <Qr input="Hello World!" ref="qrRef" />
    </template>

For more examples and customization options, see the examples.

Released under the MIT License.