qrcode.vue 3.9.1 → 3.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README-zh_cn.md DELETED
@@ -1,310 +0,0 @@
1
- # qrcode.vue
2
-
3
- ⚠️ 如果你正在使用 Vue 3,请升级 `qrcode.vue` 到 `3.x`;
4
-
5
- 🔒 如果你正在使用 Vue 2,请保持 `qrcode.vue` 的版本为 `1.x`;
6
-
7
- 一款 Vue.js 二维码组件,同时支持 Vue 2 和 Vue 3.
8
-
9
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)
10
-
11
- ## 快速开始
12
-
13
- 快速添加 `qrcode.vue` 组件到项目中
14
-
15
- ```bash
16
- npm install --save qrcode.vue # yarn add qrcode.vue
17
- ```
18
-
19
- ```
20
- dist/
21
- |--- qrcode.vue.cjs.js // CommonJS
22
- |--- qrcode.vue.esm.js // ES module
23
- |--- qrcode.vue.browser.js // UMD for browser or require.js or CommonJS
24
- |--- qrcode.vue.browser.min.js // UMD Minimum size
25
- ```
26
-
27
- ## 使用
28
-
29
- e.g.
30
-
31
- ```javascript
32
- import { createApp } from 'vue'
33
- import QrcodeVue from 'qrcode.vue'
34
-
35
- createApp({
36
- data: {
37
- value: 'https://example.com',
38
- },
39
- template: '<qrcode-vue :value="value"></qrcode-vue>',
40
- components: {
41
- QrcodeVue,
42
- },
43
- }).mount('#root')
44
- ```
45
-
46
- 或者,在独有单文件扩展 `*.vue` 中使用:
47
-
48
- ```html
49
- <template>
50
- <qrcode-vue :value="value" :size="size" level="H" />
51
- </template>
52
- <script>
53
- import QrcodeVue from 'qrcode.vue'
54
-
55
- export default {
56
- data() {
57
- return {
58
- value: 'https://example.com',
59
- size: 300,
60
- }
61
- },
62
- components: {
63
- QrcodeVue,
64
- },
65
- }
66
- </script>
67
- ```
68
-
69
- 在 Vue 3 中配合 `TypeScript` 使用:
70
-
71
- ```html
72
- <template>
73
- <qrcode-vue
74
- :value="value"
75
- :level="level"
76
- :render-as="renderAs"
77
- :background="background"
78
- :foreground='foreground'
79
- :gradient="gradient"
80
- :gradient-type="gradientType"
81
- :gradient-start-color="gradientStartColor"
82
- :gradient-end-color="gradientEndColor"
83
- :image-settings='imageSettings'
84
- :radius="radius"
85
- />
86
- </template>
87
- <script setup lang="ts">
88
- import { ref } from 'vue'
89
- import QrcodeVue from 'qrcode.vue'
90
- import type { Level, RenderAs, GradientType, ImageSettings } from 'qrcode.vue'
91
-
92
- const value = ref('qrcode')
93
- const level = ref<Level>('M')
94
- const renderAs = ref<RenderAs>('svg')
95
- const background = ref('#ffffff')
96
- const foreground = ref('#000000')
97
- const margin = ref(0)
98
-
99
- // 可传入二维码图片相关的属性,支持二维码 LOGO;
100
- const imageSettings = ref<ImageSettings>({
101
- src: 'https://github.com/scopewu.png',
102
- width: 30,
103
- height: 30,
104
- // x: 10,
105
- // y: 10,
106
- excavate: true,
107
- })
108
-
109
- // 可传入渐变相关的属性,支持渐变:
110
- const gradient = ref(false)
111
- const gradientType = ref<GradientType>('linear')
112
- const gradientStartColor = ref('#000000')
113
- const gradientEndColor = ref('#38bdf8')
114
- // 可传入圆角半径:
115
- const radius = ref(0)
116
- </script>
117
- ```
118
-
119
- ## Component props
120
-
121
- ### `value`
122
-
123
- - 类型:`string`
124
- - 默认值:`''`
125
-
126
- 二维码的内容值。
127
-
128
- ### `size`
129
-
130
- - 类型:`number`
131
- - 默认值:`100`
132
-
133
- 二维码大小。
134
-
135
- ### `render-as`
136
-
137
- - 类型:`RenderAs('canvas' | 'svg')`
138
- - 默认值:`canvas`
139
-
140
- 生成二维码的 HTML 标签,可选 `canvas` 或 `svg`。其中 `svg` 可以用于 SSR。
141
-
142
- ### `margin`
143
-
144
- - 类型:`number`
145
- - 默认值:`0`
146
-
147
- 定义空白区的宽度应该是多少。
148
-
149
- ### `level`
150
-
151
- - 类型:`Level('L' | 'M' | 'Q' | 'H')`
152
- - 默认值:`L`
153
-
154
- 二维码的容错能力等级,取值为 'L', 'M', 'Q', 'H' 之一。了解更多,[维基百科:QR_code](https://en.wikipedia.org/wiki/QR_code#Error_correction)。
155
-
156
- ### `background`
157
-
158
- - 类型:`string`
159
- - 默认值:`#ffffff`
160
-
161
- 二维码背景颜色。
162
-
163
- ### `foreground`
164
-
165
- - 类型:`string`
166
- - 默认值:`#000000`
167
-
168
- 二维码前景颜色。
169
-
170
- ### `image-settings`
171
-
172
- - 类型: `ImageSettings`
173
- - 默认值: `{}`
174
-
175
- ```ts
176
- export type ImageSettings = {
177
- src: string, // 图片的地址。
178
- x?: number, // 水平横向偏移。没有设定值时,图片剧中
179
- y?: number, // 垂直竖向偏移。没有设定值时,图片剧中
180
- height: number, // 图片的高度
181
- width: number, // 图片的宽度
182
- // 是否“挖掘”图像周围的模块。
183
- // 这意味着嵌入图像重叠的任何模块都将使用背景颜色。
184
- // 使用此选项可确保图像周围的边缘清晰。嵌入透明图像时也很有用。
185
- excavate?: boolean,
186
- borderRadius?: number, // 图片的边框圆角。
187
- }
188
- ```
189
-
190
- 二维码图片 logo 配置。
191
-
192
- ### `radius`
193
-
194
- - 类型:`number`
195
- - 默认值:`0`
196
-
197
- 每个二维码模块的圆角半径,相对于模块宽度的比例。接受 `0` 到 `0.5` 的值。
198
-
199
- - `0`(默认)- 方形模块,直角
200
- - `0.5` - 最大圆角,模块变为圆形
201
-
202
- 圆角是上下文感知的:相邻深色模块之间的内角保持直角,外角则圆角化。
203
-
204
- ```html
205
- <qrcode-vue value="test" :radius="0.35" />
206
- ```
207
-
208
- ### `id`
209
-
210
- - 类型:`string`
211
- - 默认值:`undefined`
212
-
213
- 自定义 SVG 内部元素(渐变、裁剪路径)的 ID。SSR 水合一致性需要此属性 — 传入 `useId()` 以确保服务端和客户端生成匹配的 ID。
214
-
215
- ```html
216
- <script setup>
217
- // 仅 vue 3.5+
218
- import { useId } from 'vue'
219
- const uid = useId()
220
-
221
- // vue 3.4 及以下版本
222
- // const uid = 'qrcode-1'
223
- // const uid2 = 'qrcode-2'
224
- </script>
225
- <qrcode-svg value="test" :id="uid" render-as="svg" />
226
- ```
227
-
228
- 省略时使用模块级计数器,该计数器在多请求的 SSR 环境中不安全。
229
-
230
- ### `gradient`
231
-
232
- - 类型: `boolean`
233
- - 默认值: `false`
234
-
235
- 启用二维码的渐变填充。
236
-
237
- ### `gradient-type`
238
-
239
- - 类型: `GradientType('linear' | 'radial')`
240
- - 默认值: `linear`
241
-
242
- 指定渐变类型。
243
-
244
- ### `gradient-start-color`
245
-
246
- - 类型: `string`
247
- - 默认值: `#000000`
248
-
249
- 渐变的起始颜色。
250
-
251
- ### `gradient-end-color`
252
-
253
- - 类型: `string`
254
- - 默认值: `#ffffff`
255
-
256
- 渐变的结束颜色。
257
-
258
- ### `class`
259
-
260
- - 类型:`string`
261
- - 默认值:`''`
262
-
263
- 传递给二维码根元素的类名。
264
-
265
- ## `QrcodeVue` 3.5+
266
-
267
- `QrcodeVue` 3.5+ 后导出独立的 `QrcodeCanvas` 和 `QrcodeSvg` 组件,为此修改了 rollup 的配置:
268
-
269
- ```
270
- // rollup.config.js
271
-
272
- - exports: 'default',
273
- + exports: 'named',
274
- ```
275
-
276
- 现在在 common.js 和 cdn 直接引用 `QrcodeVue` 需要使用 `default` 字段:
277
-
278
- ```js
279
- const QrcodeVue = require('qrcode.vue').default
280
- const { default: QrcodeVue, QrcodeCanvas, QrcodeSvg } = require('qrcode.vue')
281
- ```
282
-
283
- ```html
284
- <!--With HTML-->
285
- <div id="root">
286
- <p class="flex space-x">
287
- <qrcode-vue :value="test" render-as="svg"></qrcode-vue>
288
- <qrcode-canvas :value="test"></qrcode-canvas>
289
- </p>
290
- <p><input v-model="test" /></p>
291
- </div>
292
- <script src="https://cdn.jsdelivr.net/npm/vue@3.5/dist/vue.global.prod.js"></script>
293
- <script src="https://cdn.jsdelivr.net/npm/qrcode.vue@3.5/dist/qrcode.vue.browser.min.js"></script>
294
-
295
- <script>
296
- Vue.createApp({
297
- data() { return {
298
- test: 'Hello World',
299
- }},
300
- components: {
301
- QrcodeVue: QrcodeVue.default,
302
- QrcodeCanvas: QrcodeVue.QrcodeCanvas,
303
- },
304
- }).mount('#root')
305
- </script>
306
- ```
307
-
308
- ## 软件许可
309
-
310
- copyright &copy; 2021 scopewu, license by [MIT](https://github.com/scopewu/qrcode.vue/blob/main/LICENSE)