Vue3 二维码
用于生成带有徽标和样式的 QR 码的 JavaScript 库。
基础配置
安装依赖
pnpm add qrcode-vue3@1.7.11
最简示例
vue
<template>
<div>
<!-- 最简单的二维码 -->
<QRCodeVue3 :value="qrText" />
<!-- 可配置属性示例 -->
<QRCodeVue3
:width="200"
:height="200"
:value="qrText"
/>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import QRCodeVue3 from 'qrcode-vue3'
const qrText = ref<string>('https://vuejs.org/')
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

专业示例
vue
<template>
<div class="container">
<h1>qrcode-vue3 专业示例库</h1>
<div class="demo-grid">
<div class="card">
<div class="tag">最推荐:品牌定制</div>
<QRCodeVue3
:width="260"
:height="260"
value="https://vuejs.org/"
:image="vueLogo"
:qrOptions="{
typeNumber: 0,
mode: 'Byte',
errorCorrectionLevel: 'H'
}"
:imageOptions="{
hideBackgroundDots: true,
imageSize: 0.4,
margin: 8,
crossOrigin: 'anonymous'
}"
:dotsOptions="{
type: 'extra-rounded',
color: '#41b883',
gradient: {
type: 'linear',
rotation: 45,
colorStops: [
{ offset: 0, color: '#41b883' },
{ offset: 1, color: '#35495e' }
]
}
}"
:backgroundOptions="{ color: '#ffffff' }"
:download="true"
downloadButton="button-style"
:downloadOptions="{ name: 'v3-qr-brand', extension: 'png' }"
/>
<p class="desc">带 Logo、渐变色及高容错率(H)</p>
</div>
<div class="card">
<div class="tag">科技感</div>
<QRCodeVue3
:width="260"
:height="260"
value="https://github.com/di-stella/qrcode-vue3"
:dotsOptions="{
type: 'dots',
color: '#6366f1'
}"
:cornersSquareOptions="{
type: 'extra-rounded',
color: '#4f46e5'
}"
:cornersDotOptions="{
type: 'dot',
color: '#312e81'
}"
/>
<p class="desc">定制码眼形状,适合互联网产品</p>
</div>
<div class="card">
<div class="tag">极简</div>
<QRCodeVue3
:width="260"
:height="260"
value="Simplistic Design"
:dotsOptions="{
type: 'classy',
color: '#1e293b'
}"
:qrOptions="{
errorCorrectionLevel: 'M'
}"
:download="false"
/>
<p class="desc">Classy 样式,适合商务名片</p>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import QRCodeVue3 from 'qrcode-vue3'
/**
* 注意:如果外部 Logo 依然报跨域错误,
* 请将图片下载到本地 src/assets 并使用:
* import myLogo from '@/assets/logo.png'
*/
const vueLogo = "https://avatars.githubusercontent.com/u/6128107?s=200&v=4"
</script>
<style scoped>
.container {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
padding: 40px 20px;
max-width: 1100px;
margin: 0 auto;
text-align: center;
background-color: #f8fafc;
min-height: 100vh;
}
.demo-grid {
display: flex;
flex-wrap: wrap;
gap: 30px;
justify-content: center;
margin-top: 40px;
}
.card {
background: #ffffff;
padding: 30px;
border-radius: 20px;
box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
width: 320px;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
}
.tag {
position: absolute;
top: 12px;
left: 12px;
background: #f1f5f9;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
color: #64748b;
font-weight: 600;
}
.desc {
margin-top: 20px;
font-size: 14px;
color: #94a3b8;
}
/* 针对下载按钮的深度选择器优化 */
:deep(.button-style) {
margin-top: 20px;
padding: 10px 30px;
background: linear-gradient(135deg, #41b883 0%, #35495e 100%);
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
font-weight: bold;
transition: opacity 0.2s;
}
:deep(.button-style:hover) {
opacity: 0.9;
}
</style>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163

自动连接 Wi-Fi 示例
扫码后,Android 和 iOS 会自动弹出“加入网络”的提示。 格式模板:WIFI:S:<SSID>;T:<WPA|WEP>;P:<PASSWORD>;;
代码段
vue
<template>
<div class="qr-item">
<h3>Wi-Fi 快捷连接</h3>
<QRCodeVue3
:width="200"
:height="200"
value="WIFI:S:Office_Guest;T:WPA;P:password123;;"
:dotsOptions="{ type: 'rounded', color: '#0ea5e9' }"
/>
<p>账号:Office_Guest</p>
</div>
</template>
<script setup lang="ts">
import QRCodeVue3 from 'qrcode-vue3'
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
电子名片 (vCard) 示例
扫码后,手机会识别为联系人,并询问是否“添加到通讯录”。 格式模板:BEGIN:VCARD...END:VCARD
代码段
<template>
<div class="qr-item">
<h3>商务电子名片</h3>
<QRCodeVue3
:width="200"
:height="200"
value="BEGIN:VCARD
VERSION:3.0
FN:张三 (Gemini)
TEL;CELL:13800138000
EMAIL:service@example.com
ORG:科技无限公司
END:VCARD"
:dotsOptions="{ type: 'classy', color: '#334155' }"
:qrOptions="{ errorCorrectionLevel: 'M' }"
/>
<p>扫码保存联系方式</p>
</div>
</template>
<script setup lang="ts">
import QRCodeVue3 from 'qrcode-vue3'
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
地理位置 (Geo) 示例
扫码后,手机通常会询问是否在地图应用(高德/百度/Google Maps)中打开该坐标。 格式模板:geo:<lat>,<lon>
vue
<template>
<div class="qr-item">
<h3>地理位置标记</h3>
<QRCodeVue3
:width="200"
:height="200"
value="geo:31.2304,121.4737"
:dotsOptions="{ type: 'dots', color: '#f43f5e' }"
:cornersSquareOptions="{ type: 'extra-rounded', color: '#be123c' }"
/>
<p>坐标:上海人民广场</p>
</div>
</template>
<script setup lang="ts">
import QRCodeVue3 from 'qrcode-vue3'
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17