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
<!--
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-08-18 10:13:28
* @LastEditTime: 2019-08-18 15:24:32
* @LastEditors: Please set LastEditors
-->
<template>
<div>
<p class="error">{{ error }}</p>
<p class="decode-result">
Last result:
<b>{{ result }}</b>
</p>
<QrcodeStream @decode="onDecode" @init="onInit" :camera="camera"/>
</div>
</template>
<script>
import { QrcodeStream } from "vue-qrcode-reader";
export default {
components: { QrcodeStream },
data() {
return {
result: "",
camera: 'auto',
error: ""
};
},
methods: {
onDecode(result) {
this.result = result;
},
async onInit(promise) {
try {
await promise;
} catch (error) {
if (error.name === "NotAllowedError") {
this.error = "ERROR: you need to grant camera access permisson";
} else if (error.name === "NotFoundError") {
this.error = "ERROR: no camera on this device";
} else if (error.name === "NotSupportedError") {
this.error = "ERROR: secure context required (HTTPS, localhost)";
} else if (error.name === "NotReadableError") {
this.error = "ERROR: is the camera already in use?";
} else if (error.name === "OverconstrainedError") {
this.error = "ERROR: installed cameras are not suitable";
} else if (error.name === "StreamApiNotSupportedError") {
this.error = "ERROR: Stream API is not supported in this browser";
}
}
}
}
};
</script>
<style scoped>
.error {
font-weight: bold;
color: red;
}
</style>