Skip to content

QRCode

Used to generate QR codes with support for custom colors, logos, gradients, background images, and image export.

Notes

  • The component is rendered with Canvas, so the availability of logo and background-image depends on the current platform image capabilities.
  • Remote images usually need to be downloadable or readable through getImageInfo on the target platform.

Basic Usage

Basic QR Code

Set text as the QR code content.

html
<wd-qr-code text="https://wot-ui.cn" />

Custom Size

Use size to adjust the QR code size in px.

html
<wd-qr-code text="https://wot-ui.cn" :size="280" />

Custom Colors

Use color-dark and color-light to configure the dark and light colors.

html
<wd-qr-code text="https://wot-ui.cn" color-dark="#3c9cff" color-light="#f2f7ff" />

Styles

Set logo to draw a logo in the center of the QR code.

html
<wd-qr-code text="https://wot-ui.cn" logo="https://wot-ui.cn/assets/black_mao_square.png" />

Logo Style

Use logo-width, logo-height, logo-radius, logo-border-color, and logo-border-width to customize the logo.

html
<wd-qr-code
  text="https://wot-ui.cn"
  logo="https://wot-ui.cn/assets/black_mao_square.png"
  :logo-width="52"
  :logo-height="52"
  :logo-radius="12"
  logo-background-color="#ffffff"
  logo-border-color="#ffffff"
  :logo-border-width="4"
/>

Dot Styles

Use dot-type to switch between square, dots, rounded, and liquid styles, and dot-scale to adjust the scale.

html
<wd-qr-code text="https://wot-ui.cn" dot-type="dots" :dot-scale="0.9" />
<wd-qr-code text="https://wot-ui.cn" dot-type="rounded" />
<wd-qr-code text="https://wot-ui.cn" dot-type="liquid" />

Advanced Styles

Gradient Colors

After enabling enable-gradient, you can configure gradients with gradient-color or gradient-colors.

html
<wd-qr-code
  text="https://wot-ui.cn"
  enable-gradient
  :gradient-direction="45"
  :gradient-colors="['#4f46e5', '#06b6d4', '#10b981']"
/>

Background Image

Use background-image to render a background image under the QR code.

html
<wd-qr-code
  text="https://wot-ui.cn"
  background-image="https://img.yzcdn.cn/vant/apple-1.jpg"
  logo="https://wot-ui.cn/assets/black_mao_square.png"
/>

Methods

Export Image

Call exportImage through the component instance to export the QR code image and get a temporary file path.

html
<wd-qr-code ref="qrCodeRef" text="https://wot-ui.cn" />
<wd-button @click="handleExport">Export QR Code</wd-button>
ts
import { ref } from 'vue'
import type { QrCodeInstance } from '@/uni_modules/wot-ui/components/wd-qr-code/types'

const qrCodeRef = ref<QrCodeInstance>()

async function handleExport() {
  const tempFilePath = await qrCodeRef.value?.exportImage()
  console.log(tempFilePath)
}

QRCode Attributes

ParameterDescriptionTypeDefault Value
textQR code contentstring''
sizeQR code size in pxnumber200
correct-levelError correction level, available values are L, M, Q, H'L' | 'M' | 'Q' | 'H''H'
color-darkDark area colorstring'#000000'
color-lightLight area colorstring'#FFFFFF'
marginOuter margin in pxnumber0
logoLogo image URLstring''
logo-widthLogo width in pxnumber70
logo-heightLogo height in pxnumber70
logo-background-colorLogo background colorstring'#FFFFFF'
logo-radiusLogo radius in pxnumber0
logo-border-colorLogo border colorstring''
logo-border-widthLogo border width in pxnumber0
dot-typeDot style, available values are square, dots, rounded, liquid'square' | 'dots' | 'rounded' | 'liquid''square'
dot-scaleDot scale rationumber1
enable-gradientWhether to enable gradientbooleanfalse
gradient-colorGradient end colorstring'#000000'
gradient-colorsMulti-color gradient arraystring[][]
gradient-directionGradient direction, available values are diagonal, horizontal, vertical, or an angle number'diagonal' | 'horizontal' | 'vertical' | number'diagonal'
background-imageBackground image URLstring''
canvas-idCanvas id, auto-generated when omittedstring''
custom-classCustom root class namestring''
custom-styleCustom root stylestring''

QRCode Events

Event NameDescriptionCallback Parameters
clickTriggered when the component is clickedevent: Event
errorTriggered when drawing or exporting failserror: unknown

QRCode Methods

Method NameDescriptionParametersReturn Value
exportImageExport QR code image-Promise<string>

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.