# qrcode.vue
⚠️ Now when you are using Vue 3.x, please upgrade `qrcode.vue` to `3.x`
🔒 if you are using Vue 2.x, please keep using version `1.x`;
A Vue.js component to generate [QRCode](https://en.wikipedia.org/wiki/QR_code). Both support Vue 2 and Vue 3.
[简体中文](./README-zh_cn.md) | [繁體中文](./README-zh-hant.md) | [日本語](./README-ja.md)
## install
the `qrcode.vue` component can use in you Vue.js app.
```bash
npm install --save qrcode.vue # yarn add qrcode.vue
```
```
dist/
|--- qrcode.vue.cjs.js // CommonJS
|--- qrcode.vue.esm.js // ES module
|--- qrcode.vue.browser.js // UMD for browser or require.js or CommonJS
|--- qrcode.vue.browser.min.js // UMD Minimum size
```
## Usage
e.g.
```javascript
import { createApp } from 'vue'
import QrcodeVue from 'qrcode.vue'
createApp({
data: {
value: 'https://example.com',
},
template: '',
components: {
QrcodeVue,
},
}).mount('#root')
```
Or single-file components with a `*.vue` extension:
```html
```
When you use the component with Vue 3 with `TypeScript`:
```html
```
## Component props
### `value`
- Type: `string`
- Default: `''`
The value content of qrcode.
### `size`
- Type: `number`
- Default: `100`
The size of qrcode element.
### `render-as`
- Type: `RenderAs('canvas' | 'svg')`
- Default: `canvas`
Generate QRcode as `canvas` or `svg`. The prop `svg` can work on SSR.
### `margin`
- Type: `number`
- Default: `0`
Define how much wide the quiet zone should be.
### `level`
- Type: `Level('L' | 'M' | 'Q' | 'H')`
- Default: `L`
qrcode Error correction level (one of 'L', 'M', 'Q', 'H'). Know more, [wikipedia: QR_code](https://en.wikipedia.org/wiki/QR_code#Error_correction).
### `background`
- Type: `string`
- Default: `#ffffff`
The background color of qrcode.
### `foreground`
- Type: `string`
- Default: `#000000`
The foreground color of qrcode.
### `image-settings`
- Type: `ImageSettings`
- Default: `{}`
```ts
export type ImageSettings = {
src: string // The URL of image.
x?: number // The horizontal offset. When not specified, will center the image.
y?: number // The vertical offset. When not specified, will center the image.
height: number // The height of image
width: number // The height of image
excavate?: boolean // Whether or not to "excavate" the modules around the image.
borderRadius?: number // The border radius of image.
crossOrigin?: 'anonymous' | 'use-credentials' | '' // The CORS attribute for the image. Useful when exporting canvas to an image.
}
```
The settings to support qrcode image logo.
### `radius`
- Type: `number`
- Default: `0`
The corner radius of each QR module, as a ratio of the module width. Accepts values from `0` to `0.5`.
- `0` (default) - square modules with sharp corners
- `0.5` - maximum rounding, modules become circles
The rounding is context-aware: inner corners between adjacent dark modules remain sharp, while outer corners are rounded.
```html
```
### `id`
- Type: `string`
- Default: `undefined`
Custom ID for SVG internal elements (gradients, clip-paths). Required for SSR hydration consistency — pass `useId()` to ensure server and client generate matching IDs.
```html
```
When omitted, a module-level counter is used, which is not SSR-safe across multiple requests.
### `gradient`
- Type: `boolean`
- Default: `false`
Enable gradient fill for the QR code.
### `gradient-type`
- Type: `GradientType('linear' | 'radial')`
- Default: `linear`
Specify the type of gradient.
### `gradient-start-color`
- Type: `string`
- Default: `#000000`
The start color of the gradient.
### `gradient-end-color`
- Type: `string`
- Default: `#ffffff`
The end color of the gradient.
### `class`
- Type: `string`
- Default: `''`
The class name of qrcode element.
## Template Ref Methods (`QrcodeCanvas` / `QrcodeSvg`)
Both `QrcodeCanvas` and `QrcodeSvg` expose the following methods via template ref. `QrcodeVue` forwards them based on the current `render-as`.
### `QrcodeCanvas`
```html
```
| Method | Signature | Description |
| ----------- | ---------------------------------------------------------- | ------------------------------------------------- |
| `toDataURL` | `(type?: string, quality?: number) => string \| undefined` | Convert the canvas to a data URL. |
| `download` | `(filename?: string) => void` | Trigger a download of the QR code as a PNG image. |
> **CORS note:** When the QR code includes a cross-origin logo image, make sure to set `imageSettings.crossOrigin: 'anonymous'` and that the image server responds with the `Access-Control-Allow-Origin` header. Otherwise the canvas becomes "tainted" and `toDataURL` / `download` will throw a `SecurityError`.
### `QrcodeSvg`
```html
```
| Method | Signature | Description |
| ----------- | ----------------------------- | -------------------------------------------------- |
| `toDataURL` | `() => string \| undefined` | Convert the SVG element to a data URL. |
| `download` | `(filename?: string) => void` | Trigger a download of the QR code as an SVG image. |
## `QrcodeVue` 3.5+
`QrcodeVue` 3.5+ exports separate `QrcodeCanvas` and `QrcodeSvg` components, for which the rollup configuration has been modified:
```
// rollup.config.js
- exports: 'default',
+ exports: 'named',
```
Direct references to `QrcodeVue` in common.js and cdn now require the `default` field:
```js
const QrcodeVue = require('qrcode.vue').default
const { default: QrcodeVue, QrcodeCanvas, QrcodeSvg } = require('qrcode.vue')
```
```html
```
## AI / LLM support
qrcode.vue ships resources that help AI coding assistants use this library correctly:
- [`llms.txt`](./llms.txt) — a compact, LLM-friendly summary of the library in [llmstxt.org](https://llmstxt.org) format.
- [`skills/qrcode-vue/SKILL.md`](./skills/qrcode-vue/SKILL.md) — an [Agent Skills](https://agentskills.io)–format skill with the props table, recipes, and pitfalls. Copy it into your assistant's skills directory (e.g. `~/.agents/skills/` or `.claude/skills/`) to give the agent expert knowledge of qrcode.vue.
Both files are also included in the npm package.
## License
copyright © 2021 @scopewu, license by [MIT](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)