File tree Expand file tree Collapse file tree 1 file changed +80
-0
lines changed Expand file tree Collapse file tree 1 file changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html >
3+
4+ < head >
5+ < title > Vue QR-Code Reader DEMO</ title >
6+
7+ < meta charset ="utf-8 ">
8+ < meta name ="viewport " content ="width=device-width, initial-scale=1, shrink-to-fit=no ">
9+
10+ < script src ="https://unpkg.com/vue@2/dist/vue.min.js "> </ script >
11+ < script src ="https://unpkg.com/vue-qrcode-reader@2/dist/vue-qrcode-reader.browser.js "> </ script >
12+ < link rel ="stylesheet " href ="https://unpkg.com/vue-qrcode-reader@2/dist/vue-qrcode-reader.css ">
13+
14+ < style >
15+ p {
16+ padding : 20px ;
17+ }
18+
19+ .error {
20+ color : red;
21+ font-weight : bold;
22+ }
23+ </ style >
24+ </ head >
25+
26+ < body >
27+ < div id ="app ">
28+ < p >
29+ Last result: < b > {{ decodedContent }}</ b >
30+ </ p >
31+
32+ < p class ="error ">
33+ {{ errorMessage }}
34+ </ p >
35+
36+ < qrcode-stream :torch ="true " @init ="onInit "> </ qrcode-stream >
37+ </ div >
38+ </ body >
39+ < script >
40+ new Vue ( {
41+ el : '#app' ,
42+
43+ data ( ) {
44+ return {
45+ decodedContent : '' ,
46+ errorMessage : ''
47+ }
48+ } ,
49+
50+ methods : {
51+ onDecode ( content ) {
52+ this . decodedContent = content
53+ } ,
54+
55+ onInit ( promise ) {
56+ promise . then ( ( { capabilities } ) => {
57+ console . log ( 'Successfully initilized! Ready for scanning now!' )
58+ } )
59+ . catch ( error => {
60+ if ( error . name === 'NotAllowedError' ) {
61+ this . errorMessage = 'Hey! I need access to your camera'
62+ } else if ( error . name === 'NotFoundError' ) {
63+ this . errorMessage = 'Do you even have a camera on your device?'
64+ } else if ( error . name === 'NotSupportedError' ) {
65+ this . errorMessage = 'Seems like this page is served in non-secure context (HTTPS, localhost or file://)'
66+ } else if ( error . name === 'NotReadableError' ) {
67+ this . errorMessage = 'Couldn\'t access your camera. Is it already in use?'
68+ } else if ( error . name === 'OverconstrainedError' ) {
69+ this . errorMessage = 'Constraints don\'t match any installed camera. Did you asked for the front camera although there is none?'
70+ } else {
71+ this . errorMessage = 'UNKNOWN ERROR: ' + error . message
72+ }
73+ } )
74+ }
75+ }
76+ } )
77+
78+ </ script >
79+
80+ </ html >
You can’t perform that action at this time.
0 commit comments