LWC のスキャンコードで最新の scan() API および dismiss() API を使用して、開発環境を簡素化することをお勧めします。従来の beginCapture() API、resumeCapture() API、endCapture() API は引き続き使用できますが、将来のリリースで廃止される予定です。
Note
構文
1import { getBarcodeScanner } from 'lightning/mobileCapabilities';2beginCapture(options: BarcodeScannerOptions): Promise<Object>
1myScanner2 .beginCapture(scanningOptions)3 .then((result)=>{4 // Do something with the result of the scan5 console.log(result);6 this.scannedBarcode = result.value;7})8 .catch((error)=>{9 // Handle cancellation and scanning errors here10 console.error(error);11})12 .finally(()=>{13 myScanner.endCapture();14});
この関数がコールされると、モバイル OS スキャンユーザインターフェースがモバイルデバイスに表示されます。ユーザは、カメラをバーコードに向けて、バーコードが認識されるまで待ちます。