qrcode-vue
This `qrcode-vue` package offers a Vue.js component for rendering QR codes directly within Vue applications. It utilizes the underlying `qr.js` library for all core QR code encoding functionalities, simplifying integration for Vue 2 developers. Key features include dynamic adjustment of QR code size, customization of background and foreground colors, and the ability to embed a logo image at the center of the generated QR code. While the latest version available on npm is 1.2.0, reportedly published approximately a year ago, the linked GitHub repository (l-ll/qrcode-vue) shows a severe lack of recent development, with the last commits and official releases (like v1.0.0) dating back to 2017. This strong indication of abandonment means the package is not actively maintained and lacks crucial updates or support for modern Vue ecosystems, particularly Vue 3, with which it is not inherently compatible without significant refactoring. Its release cadence is effectively non-existent, making it a risky choice for new projects.
Common errors
-
[Vue warn]: Unknown custom element: <qrcode-vue> - did you register the component correctly?
cause The `qrcode-vue` component was imported but not registered either locally in a component or globally in the Vue instance.fixEnsure `QrcodeVue` is listed in the `components` option of your Vue component: `components: { QrcodeVue }` or globally registered via `Vue.component('qrcode-vue', QrcodeVue)`. -
Error: Tainted canvases may not be exported. Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement'
cause Attempting to generate a QR code with a logo URL from a different origin without proper CORS headers.fixHost the logo image on the same domain as your application, ensure the image server sends `Access-Control-Allow-Origin` headers, or convert the logo image to a base64 data URL. -
TypeError: Cannot read properties of undefined (reading 'value')
cause The `value` prop, which is mandatory for QR code generation, was not provided or was `undefined`.fixAlways provide a valid string for the `:value` prop, e.g., `:value="myUrl"`.
Warnings
- breaking This package is built for Vue 2.x and is not directly compatible with Vue 3.x applications. Attempting to use it in a Vue 3 project will result in runtime errors due to fundamental API changes.
- gotcha The primary GitHub repository (l-ll/qrcode-vue) has been inactive since 2017, and while npm shows a version 1.2.0 published roughly a year ago, the project is effectively abandoned. This means no new features, bug fixes, or security patches are expected.
- gotcha Embedding a logo via the `logo` prop can lead to Cross-Origin Resource Sharing (CORS) errors if the logo image is hosted on a different domain than your application and does not provide appropriate CORS headers.
- gotcha The underlying `qr.js` library, on which `qrcode-vue` depends, might not receive timely security updates. Using an unmaintained QR code generator could pose security risks, especially if generating QR codes from untrusted input.
Install
-
npm install qrcode-vue -
yarn add qrcode-vue -
pnpm add qrcode-vue
Imports
- QrcodeVue
import { QrcodeVue } from 'qrcode-vue';import QrcodeVue from 'qrcode-vue'; // In a Vue component's script section
- QrcodeVue
import { QrcodeVue } from 'qrcode-vue'; Vue.component('qrcode-vue', QrcodeVue);import QrcodeVue from 'qrcode-vue'; Vue.component('qrcode-vue', QrcodeVue); // For global registration in main.js - QrcodeVue
const QrcodeVue = require('qrcode-vue'); // Will return an object { default: Component }const QrcodeVue = require('qrcode-vue').default;
Quickstart
<template>
<div id="app">
<p>Scan this QR code!</p>
<qrcode-vue
:size="size"
:value="value"
:logo="logo"
:bgColor="bgColor"
:fgColor="fgColor"
level="H"
></qrcode-vue>
<p>Current value: {{ value }}</p>
<p>Size: {{ size }}px</p>
<p>
<button @click="changeValue">Change Value</button>
<button @click="changeSize">Toggle Size</button>
</p>
</div>
</template>
<script>
import QrcodeVue from 'qrcode-vue';
export default {
components: {
QrcodeVue
},
data () {
return {
size: 160,
bgColor: '#ffffff',
fgColor: '#000000',
value: 'https://checklist.day/quickstart-example',
logo: 'https://vuejs.org/images/logo.png' // Using Vue logo for example
}
},
methods: {
changeValue() {
this.value = this.value === 'https://checklist.day/quickstart-example'
? 'https://github.com/l-ll/qrcode-vue'
: 'https://checklist.day/quickstart-example';
},
changeSize() {
this.size = this.size === 160 ? 200 : 160;
}
}
}
</script>