QR Code component for generating QR codes. Invoke when user needs to generate or display QR codes for URLs, text, or data encoding in Naive UI.
QR Code component for generating customizable QR codes with support for icons, colors, and different render types.
Use this component when:
Invoke this skill when:
| Name | Type | Default | Description |
|---|---|---|---|
| background-color | string | '#FFF' | QR code background color (hex format). |
| color | string | '#000' | QR code color (hex format). |
| error-correction-level | 'L' | 'M' | 'Q' | 'H' | 'M' | Error correction level. |
| icon-background-color | string | '#FFF' | Icon background color. |
| icon-border-radius | number | 4 | Icon background border radius. |
| icon-size | number | 40 | Icon size in pixels. |
| icon-src | string | undefined | Icon image URL. |
| padding | number | string | 12 | QR code padding. |
| size | number | 100 | QR code size in pixels. |
| type | 'canvas' | 'svg' | 'canvas' | Render type. |
| value | string | '' | Text/URL to encode. |
| Level | Recovery Rate | Use Case |
|---|---|---|
| L (Low) | ~7% | Clean environments |
| M (Medium) | ~15% | Default, general use |
| Q (Quarter) | ~25% | Moderate damage risk |
| H (High) | ~30% | With icons, high damage risk |
<template>
<n-space vertical>
<n-qr-code :value="text" />
<n-input v-model:value="text" :maxlength="60" placeholder="Enter text or URL" />
</n-space>
</template>
<script setup>
import { ref } from 'vue'
const text = ref('https://www.naiveui.com/')
</script>
<template>
<n-qr-code
value="https://www.naiveui.com/"
icon-src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
error-correction-level="H"
/>
</template>
<template>
<n-flex>
<n-qr-code value="https://www.naiveui.com/" color="#18a058" />
<n-qr-code
value="https://www.naiveui.com/"
color="#409eff"
background-color="#F5F5F5"
/>
</n-flex>
</template>
<template>
<n-space vertical>
<n-slider v-model:value="size" :min="60" :max="300" />
<n-qr-code value="https://www.naiveui.com/" :size="size" />
</n-space>
</template>
<script setup>
import { ref } from 'vue'
const size = ref(100)
</script>
<template>
<n-space vertical>
<n-qr-code id="qr-code" value="https://www.naiveui.com/" />
<n-button @click="handleDownload">
Download QR Code
</n-button>
</n-space>
</template>
<script setup>
const handleDownload = () => {
const canvas = document.querySelector('#qr-code canvas')
if (canvas) {
const url = canvas.toDataURL('image/png')
const link = document.createElement('a')
link.download = 'qrcode.png'
link.href = url
link.click()
}
}
</script>
<template>
<n-card title="QR Code Generator">
<n-space vertical>
<n-input v-model:value="content" placeholder="Enter content" />
<n-color-picker v-model:value="qrColor" />
<n-slider v-model:value="qrSize" :min="100" :max="300" />
<n-qr-code
:value="content"
:color="qrColor"
:size="qrSize"
/>
</n-space>
</n-card>
</template>
<script setup>
import { ref } from 'vue'
const content = ref('https://example.com')
const qrColor = ref('#000000')
const qrSize = ref(150)
</script>
<template>
<n-space vertical>
<n-qr-code
:value="longText"
:error-correction-level="errorCorrectionLevel"
/>
<n-radio-group v-model:value="errorCorrectionLevel">
<n-radio-button value="L" label="Low (7%)" />
<n-radio-button value="M" label="Medium (15%)" />
<n-radio-button value="Q" label="Quarter (25%)" />
<n-radio-button value="H" label="High (30%)" />
</n-radio-group>
</n-space>
</template>
<script setup>
import { ref } from 'vue'
const longText = ref('A longer text that requires more error correction')
const errorCorrectionLevel = ref('M')
</script>
<template>
<n-space>
<div>
<n-text>Canvas:</n-text>
<n-qr-code :value="text" type="canvas" />
</div>
<div>
<n-text>SVG:</n-text>
<n-qr-code :value="text" type="svg" />
</div>
</n-space>
</template>
<script setup>
import { ref } from 'vue'
const text = ref('https://www.naiveui.com/')
</script>
<template>
<n-card title="Scan to Visit" style="width: 250px">
<n-space vertical align="center">
<n-qr-code
:value="url"
:size="180"
icon-src="/logo.png"
error-correction-level="H"
/>
<n-text depth="3">{{ url }}</n-text>
<n-button size="small" @click="copyUrl">
Copy Link
</n-button>
</n-space>
</n-card>
</template>
<script setup>
import { useMessage } from 'naive-ui'
const url = 'https://www.naiveui.com/'
const message = useMessage()
const copyUrl = async () => {
await navigator.clipboard.writeText(url)
message.success('Link copied!')
}
</script>
<template>
<n-flex>
<n-qr-code
value="https://www.naiveui.com/"
icon-src="/logo.png"
:icon-size="32"
icon-background-color="#333"
error-correction-level="H"
/>
<n-qr-code
value="https://www.naiveui.com/"
icon-src="/logo.png"
:icon-border-radius="8"
error-correction-level="H"
/>
</n-flex>
</template>
Use high error correction with icons: Set error-correction-level to 'H' when using icons
<n-qr-code icon-src="logo.png" error-correction-level="H" />
Use hex color format: Colors must be in hex format
<n-qr-code color="#18a058" background-color="#ffffff" />
Choose appropriate size: Ensure QR code is large enough to scan
<n-qr-code :size="150" /> <!-- Minimum recommended for easy scanning -->
Test scannability: Always test generated QR codes with actual scanners
// Test with various devices and lighting conditions
Use SVG for scalability: Choose SVG type when scaling is needed
<n-qr-code type="svg" /> <!-- Better for print or responsive designs -->
Keep content concise: Shorter content creates simpler QR codes
// Use URL shorteners for long URLs
const shortUrl = 'https://short.url/abc123'