You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.4 KiB
59 lines
1.4 KiB
10 months ago
|
<template>
|
||
|
<div>
|
||
|
<p class="error">{{ error }}</p>
|
||
|
|
||
|
<p class="decode-result">Last result: <b>{{ result }}</b></p>
|
||
|
|
||
|
<qrcode-stream @decode="onDecode" @init="onInit" />
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import { QrcodeStream } from '../../../../src'
|
||
|
|
||
|
export default {
|
||
|
|
||
|
components: { QrcodeStream },
|
||
|
|
||
|
data () {
|
||
|
return {
|
||
|
result: '',
|
||
|
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>
|