0.1.0 • Published 6 months ago
@itsjining/svelte-scan-qrcode v0.1.0
svelte-scan-qrcode
Scan QR Code on browser by open camera or upload QR Code image. Support open cameras on Android and iOS browsers.
Demo
How to use
Install @itsjining/svelte-scan-qrcode
npm install --save @itsjining/svelte-scan-qrcodeSimple with
bind:scanResultto get scan result<script lang="ts"> import { ScanQRCode } from "@itsjining/svelte-scan-qrcode"; let result = ""; </script> <ScanQRCode bind:scanResult={result} options={{}} />Custom with
enableQRCodeReaderButtonandoptions<script lang="ts"> import { goto } from "$app/navigation"; import { ScanQRCode } from "@itsjining/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(), }} />
Props
- scanResult
- Type
string. - Use
bind:scanResultto get scan result.
- Type
- enableQRCodeReaderButton
- Type
boolean. - Set to true for enable upload QR Code image button. After user uploaded image
@itsjining/svelte-scan-qrcodepackage will read QR Code from image.
- Type
- options
- Types
{ onPermissionError?: Function; onResulted?: Function; }- onPermissionError function will call if
@itsjining/svelte-scan-qrcodepackage request camera get rejected. - onResulted function will call if the
@itsjining/svelte-scan-qrcodepackage gets the scan result from QR Code.
- onPermissionError function will call if
- Types
- scanResult
0.1.0
6 months ago