Kill the QRcode scanner when exiting the view
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import {
|
||||
Html5QrcodeScanner,
|
||||
type Html5QrcodeResult,
|
||||
@@ -37,6 +37,12 @@
|
||||
);
|
||||
scanner.render(onScanSuccess, onScanFailure);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (scanner) {
|
||||
scanner.clear().catch(() => {});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div id="qr-scanner" class="w-full h-full max-w-none overflow-hidden rounded-sm"></div>
|
||||
|
||||
Reference in New Issue
Block a user