Skip to content

Commit 71ccf87

Browse files
authored
feat: support dataURL change event (#146)
1 parent 5224145 commit 71ccf87

File tree

11 files changed

+171
-15
lines changed

11 files changed

+171
-15
lines changed

.changeset/polite-lions-swim.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"vue-qrcode": minor
3+
"vue-qrious": minor
4+
---
5+
6+
feat: support dataURL `change` event

.vitepress/components/VueQrcodeDemo.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,20 @@
152152
</ul>
153153
<a
154154
download="qrcode-demo.png"
155-
href
155+
:href="dataUrl"
156156
>
157157
<vue-qrcode
158158
v-bind="qrcodeProps"
159+
@change="onChange"
159160
@error="onError"
160161
/>
161162
</a>
163+
<div
164+
v-if="dataUrl"
165+
class="data-url"
166+
>
167+
{{ dataUrl }}
168+
</div>
162169
</div>
163170
</template>
164171
<script lang="ts">
@@ -212,6 +219,7 @@ export default defineComponent({
212219
quality: 0.92,
213220
value: DEFAULT_TEXT as QRCodeValue,
214221
manualMode: false,
222+
dataUrl: null,
215223
}
216224
},
217225
computed: {
@@ -239,6 +247,9 @@ export default defineComponent({
239247
removeValue(index: number) {
240248
;(this.value as QRCodeSegment[]).splice(index, 1)
241249
},
250+
onChange(dataUrl: string) {
251+
this.dataUrl = dataUrl
252+
},
242253
onError(err: Error) {
243254
window.alert(err.message)
244255
},
@@ -281,4 +292,9 @@ export default defineComponent({
281292
width: 100%;
282293
}
283294
}
295+
296+
.data-url {
297+
max-width: 100%;
298+
overflow-x: auto;
299+
}
284300
</style>

.vitepress/components/VueQriousDemo.vue

+26-2
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,20 @@
7474
<client-only>
7575
<a
7676
download="qrious-demo.png"
77-
href
77+
:href="dataUrl"
7878
>
79-
<vue-qrious v-bind="qriousProps" />
79+
<vue-qrious
80+
v-bind="qriousProps"
81+
@change="onChange"
82+
@error="onError"
83+
/>
8084
</a>
85+
<div
86+
v-if="dataUrl"
87+
class="data-url"
88+
>
89+
{{ dataUrl }}
90+
</div>
8191
</client-only>
8292
</div>
8393
</template>
@@ -115,13 +125,22 @@ export default defineComponent({
115125
padding: 0,
116126
size: 100,
117127
value: 'http://www.1stg.me',
128+
dataUrl: null,
118129
}
119130
},
120131
computed: {
121132
qriousProps() {
122133
return pick(this, QRIOUS_PROPS)
123134
},
124135
},
136+
methods: {
137+
onChange(dataUrl: string) {
138+
this.dataUrl = dataUrl
139+
},
140+
onError(err: Error) {
141+
window.alert(err.message)
142+
},
143+
},
125144
})
126145
</script>
127146
<style lang="scss">
@@ -160,4 +179,9 @@ export default defineComponent({
160179
width: 100%;
161180
}
162181
}
182+
183+
.data-url {
184+
max-width: 100%;
185+
overflow-x: auto;
186+
}
163187
</style>

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ npm i vue-{qrcode,qrious}
6464

6565
## Backers
6666

67+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
68+
6769
| 1stG | RxTS | UnTS |
6870
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
6971
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

index.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141

4242
This repository is a monorepo managed by [Changesets][] what means we actually publish several packages to npm from same codebase, including:
4343

44-
| Package | Description | Version | Peer Dependencies | Dependencies |
45-
| ------------------------------------- | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
46-
| [`vue-qrcode`](/packages/vue-qrcode/) | 🤳 A Vue component for QR code generation with [qrcode][] | [![npm](https://img.shields.io/npm/v/vue-qrcode.svg)](https://www.npmjs.com/package/vue-qrcode) | [![David Peer](https://img.shields.io/david/peer/rx-ts/vue.svg?path=packages/vue-qrcode)](https://david-dm.org/rx-ts/vue?path=packages/vue-qrcode&type=peer) | [![David](https://img.shields.io/david/rx-ts/vue.svg?path=packages/vue-qrcode)](https://david-dm.org/rx-ts/vue?path=packages/vue-qrcode) |
47-
| [`vue-qrious`](/packages/vue-qrious/) | 🤳 A Vue component for QR code generation with [qrious][] | [![npm](https://img.shields.io/npm/v/vue-qrious.svg)](https://www.npmjs.com/package/vue-qrious) | [![David Peer](https://img.shields.io/david/peer/rx-ts/vue.svg?path=packages/vue-qrious)](https://david-dm.org/rx-ts/vue?path=packages/vue-qrious&type=peer) | [![David](https://img.shields.io/david/rx-ts/vue.svg?path=packages/vue-qrious)](https://david-dm.org/rx-ts/vue?path=packages/vue-qrious) |
44+
| Package | Description | Version |
45+
| ------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
46+
| [`vue-qrcode`](/packages/vue-qrcode/) | 🤳 A Vue component for QR code generation with [qrcode][] | [![npm](https://img.shields.io/npm/v/vue-qrcode.svg)](https://www.npmjs.com/package/vue-qrcode) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/vue-qrcode) |
47+
| [`vue-qrious`](/packages/vue-qrious/) | 🤳 A Vue component for QR code generation with [qrious][] | [![npm](https://img.shields.io/npm/v/vue-qrious.svg)](https://www.npmjs.com/package/vue-qrious) [![View changelog](https://img.shields.io/badge/changelog-explore-brightgreen)](https://changelogs.xyz/vue-qrious) |
4848

4949
## Install
5050

@@ -64,6 +64,8 @@ npm i vue-{qrcode,qrious}
6464

6565
## Backers
6666

67+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
68+
6769
| 1stG | RxTS | UnTS |
6870
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
6971
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

packages/vue-qrcode/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Demo](#demo)
88
- [Usage](#usage)
99
- [Available Props](#available-props)
10+
- [Available Events](#available-events)
1011
- [Sponsors](#sponsors)
1112
- [Backers](#backers)
1213
- [Changelog](#changelog)
@@ -20,15 +21,28 @@
2021

2122
```vue
2223
<template>
23-
<vue-qrcode value="https://www.1stg.me" />
24+
<vue-qrcode
25+
value="https://www.1stg.me"
26+
@change="onDataUrlChange"
27+
/>
2428
</template>
2529
<script>
2630
import VueQrcode from 'vue-qrcode'
2731
2832
export default {
33+
data() {
34+
return {
35+
dataUrl: null,
36+
}
37+
},
2938
components: {
3039
VueQrcode,
3140
},
41+
methods: {
42+
onDataUrlChange(dataUrl) {
43+
this.dataUrl = dataUrl
44+
},
45+
},
3246
}
3347
</script>
3448
```
@@ -49,6 +63,12 @@ export default {
4963
| `quality` | `number`(0-1) | `0.92` |
5064
| `value` | `string \|Array<{ data: string; mode?: string }>` | N/A |
5165

66+
## Available Events
67+
68+
| event | type |
69+
| ------ | ----------------- |
70+
| change | `dataUrl: string` |
71+
5272
## Sponsors
5373

5474
| 1stG | RxTS | UnTS |
@@ -57,6 +77,8 @@ export default {
5777

5878
## Backers
5979

80+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
81+
6082
| 1stG | RxTS | UnTS |
6183
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
6284
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

packages/vue-qrcode/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Demo](#demo)
88
- [Usage](#usage)
99
- [Available Props](#available-props)
10+
- [Available Events](#available-events)
1011
- [Sponsors](#sponsors)
1112
- [Backers](#backers)
1213
- [Changelog](#changelog)
@@ -49,6 +50,12 @@ export default {
4950
| `quality` | `number`(0-1) | `0.92` |
5051
| `value` | `string \|Array<{ data: string; mode?: string }>` | N/A |
5152

53+
## Available Events
54+
55+
| event | type |
56+
| ------ | ----------------- |
57+
| change | `dataUrl: string` |
58+
5259
## Sponsors
5360

5461
| 1stG | RxTS | UnTS |
@@ -57,6 +64,8 @@ export default {
5764

5865
## Backers
5966

67+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
68+
6069
| 1stG | RxTS | UnTS |
6170
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
6271
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

packages/vue-qrcode/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export default defineComponent({
108108
)
109109
.then(dataUrl => {
110110
dataUrlRef.value = dataUrl
111+
emit('change', dataUrl)
111112
})
112113
.catch((err: unknown) => emit('error', err))
113114
}

packages/vue-qrious/README.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
> 🤳 A Vue component for QR code generation with [qrious](https://github.com/neocotic/qrious)
44
5+
## TOC <!-- omit in toc -->
6+
7+
- [Demo](#demo)
8+
- [Usage](#usage)
9+
- [Available Props](#available-props)
10+
- [Available Events](#available-events)
11+
- [Sponsors](#sponsors)
12+
- [Backers](#backers)
13+
- [Changelog](#changelog)
14+
- [License](#license)
15+
516
## Demo
617

718
<VueQriousDemo />
@@ -10,15 +21,28 @@
1021

1122
```vue
1223
<template>
13-
<vue-qrious value="https://www.1stg.me" />
24+
<vue-qrious
25+
value="https://www.1stg.me"
26+
@change="onDataUrlChange"
27+
/>
1428
</template>
1529
<script>
1630
import VueQrious from 'vue-qrious'
1731
1832
export default {
33+
data() {
34+
return {
35+
dataUrl: null,
36+
}
37+
},
1938
components: {
2039
VueQrious,
2140
},
41+
methods: {
42+
onDataUrlChange(dataUrl) {
43+
this.dataUrl = dataUrl
44+
},
45+
},
2246
}
2347
</script>
2448
```
@@ -35,7 +59,13 @@ export default {
3559
| `mime` | `string` ("image/png", "image/jpeg") | `"image/png"` |
3660
| `padding` | `number` | `null` |
3761
| `size` | `number` | `100` |
38-
| `value` | `string` |
62+
| `value` | `string` | N/A |
63+
64+
## Available Events
65+
66+
| event | type |
67+
| ------ | ----------------- |
68+
| change | `dataUrl: string` |
3969

4070
## Sponsors
4171

@@ -45,6 +75,8 @@ export default {
4575

4676
## Backers
4777

78+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
79+
4880
| 1stG | RxTS | UnTS |
4981
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
5082
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

packages/vue-qrious/index.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
> 🤳 A Vue component for QR code generation with [qrious](https://github.com/neocotic/qrious)
44
5+
## TOC <!-- omit in toc -->
6+
7+
- [Demo](#demo)
8+
- [Usage](#usage)
9+
- [Available Props](#available-props)
10+
- [Available Events](#available-events)
11+
- [Sponsors](#sponsors)
12+
- [Backers](#backers)
13+
- [Changelog](#changelog)
14+
- [License](#license)
15+
516
## Demo
617

718
<VueQriousDemo />
@@ -10,15 +21,28 @@
1021

1122
```vue
1223
<template>
13-
<vue-qrious value="https://www.1stg.me" />
24+
<vue-qrious
25+
value="https://www.1stg.me"
26+
@change="onDataUrlChange"
27+
/>
1428
</template>
1529
<script>
1630
import VueQrious from 'vue-qrious'
1731
1832
export default {
33+
data() {
34+
return {
35+
dataUrl: null,
36+
}
37+
},
1938
components: {
2039
VueQrious,
2140
},
41+
methods: {
42+
onDataUrlChange(dataUrl) {
43+
this.dataUrl = dataUrl
44+
},
45+
},
2246
}
2347
</script>
2448
```
@@ -35,7 +59,13 @@ export default {
3559
| `mime` | `string` ("image/png", "image/jpeg") | `"image/png"` |
3660
| `padding` | `number` | `null` |
3761
| `size` | `number` | `100` |
38-
| `value` | `string` |
62+
| `value` | `string` | N/A |
63+
64+
## Available Events
65+
66+
| event | type |
67+
| ------ | ----------------- |
68+
| change | `dataUrl: string` |
3969

4070
## Sponsors
4171

@@ -45,6 +75,8 @@ export default {
4575

4676
## Backers
4777

78+
[![Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)
79+
4880
| 1stG | RxTS | UnTS |
4981
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
5082
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |

0 commit comments

Comments
 (0)