forked from mebjas/html5-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
66 lines (59 loc) · 2.08 KB
/
index.html
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
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML5 QR Code with Vue js</title>
<link rel="stylesheet" href="/vuejs/style.css">
</head>
<body>
<!-- Vue Js App Code -->
<div id="app">
<div class="header" style="margin-bottom: 20px;">{{ header }}</div>
<div class="section" style="width: 500px; margin: auto;">
<qrcode-scanner
v-bind:qrbox="250"
v-bind:fps="10"
style="width: 500px;">
</qrcode-scanner>
</div>
<div class="footer" style="margin-bottom: 20px;">{{ result }}</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/html5-qrcode"></script>
<script>
Vue.component('qrcode-scanner', {
props: {
qrbox: Number,
fps: Number,
},
template: `<div id="qr-code-full-region"></div>`,
mounted: function () {
var $this = this;
var config = { fps: this.fps ? this.fps : 10 };
if (this.qrbox) {
config['qrbox'] = this.qrbox;
}
function onScanSuccess(decodedText, decodedResult) {
$this.$root.$emit('decodedCode', decodedText, decodedResult);
}
var html5QrcodeScanner = new Html5QrcodeScanner(
"qr-code-full-region", config);
html5QrcodeScanner.render(onScanSuccess);
}
});
var app = new Vue({
el: '#app',
data: {
header: 'Html5-qrcode using vue.js',
result: ''
},
created: function () {
this.$root.$on('decodedCode', function (decodedText, decodedResult) {
this.decodedText = decodedText;
}.bind(this));
}
});
</script>
</body>
</html>