Install @kuiper/svelte-scan-qrcode
npm install --save @kuiper/svelte-scan-qrcode
Simple with bind:scanResult
to get scan result
<script lang="ts">
import { ScanQRCode } from "@kuiper/svelte-scan-qrcode";
let result = "";
</script>
<ScanQRCode bind:scanResult={result} options={{}} />
Custom with enableQRCodeReaderButton
and options
<script lang="ts">
import { goto } from "$app/navigation";
import { ScanQRCode } from "@kuiper/svelte-scan-qrcode";
let result = "";
function _onPermissionError() {
alert("Permission rejected");
location.reload();
}
function _onResulted() {
if (result.includes("love")) {
goto("/result"); // go to result page
}
}
</script>
<ScanQRCode
bind:scanResult={result}
enableQRCodeReaderButton={true}
options={{
onPermissionError: () => _onPermissionError(),
onResulted: () => _onResulted(),
}}
/>