Я новичок в NativeScript, и мне нужно отсканировать QR-код. Я попытался использовать плагин nativescript-barcodescanner с Vue. js и не смог, при запуске всех демонстраций произошла ошибка. Я пытался найти примеры, но не нашел ничего, что могло бы мне помочь.
Я написал этот код на основе демо - vue, но он тоже не сработал:
<template>
<Page>
<ActionBar title="BarcodeScanner demo"></ActionBar>
<StackLayout>
<Button text="back camera" @tap="doScanWithBackCamera"></Button>
<BarcodeScanner
row="1"
height="300"
formats="QR_CODE, EAN_13, UPC_A"
beepOnScan="true"
reportDuplicates="true"
preferFrontCamera="false"
@scanResult="onScanResult">
</BarcodeScanner>
</StackLayout>
</Page>
</template>
<script>
var BarcodeScanner = require("nativescript-barcodescanner").BarcodeScanner;
export default {
data() {
return {
}
},
methods: {
onScanResult(evt) {
console.log(`onScanResult: ${evt.text} (${evt.format})`);
},
doScanWithBackCamera() {
this.scan();
},
scan() {
var barcodescanner = new BarcodeScanner();
barcodescanner.scan({
cancelLabel: "EXIT. Also, try the volume buttons!", // iOS only, default 'Close'
cancelLabelBackgroundColor: "#333333", // iOS only, default '#000000' (black)
message: "Use the volume buttons for extra light", // Android only, default is 'Place a barcode inside the viewfinder rectangle to scan it.'
showFlipCameraButton: true, // default false
showTorchButton: true, // iOS only, default false
resultDisplayDuration: 500, // Android only, default 1500 (ms), set to 0 to disable echoing the scanned text
beepOnScan: true, // Play or Suppress beep on scan (default true)
openSettingsIfPermissionWasPreviouslyDenied: true, // On iOS you can send the user to the settings app if access was previously denied
closeCallback: () => {
console.log("Scanner closed @ " + new Date().getTime());
}
}).then(
function (result) {
console.log("--- scanned: " + result.text);
// Note that this Promise is never invoked when a 'continuousScanCallback' function is provided
setTimeout(function () {
// if this alert doesn't show up please upgrade to {N} 2.4.0+
alert({
title: "Scan result",
message: "Format: " + result.format + ",\nValue: " + result.text,
okButtonText: "OK"
});
}, 500);
},
function (errorMessage) {
console.log("No scan. " + errorMessage);
}
);
}
}
}
</script>
<style scoped>
ActionBar {
background-color: #53ba82;
color: #ffffff;
}
</style>
Ошибка при сборке demo- vue:
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\demo-vue\tsconfig.json
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR
[20-05-06 11:10:12.631] (CLI) TS2688: Cannot find type definition file for 'node'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) C:/NativeScript/nativescript-barcodescanner-master/src/barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts(2,59)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/application'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) C:/NativeScript/nativescript-barcodescanner-master/src/barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts(3,28)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/application'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) C:/NativeScript/nativescript-barcodescanner-master/src/barcodescanner.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner.ts(4,24)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/utils/utils'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts(1,29)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/ui/content-view'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts(2,26)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/ui/core/properties'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts(3,34)
[20-05-06 11:10:12.631] (CLI) TS2307: Cannot find module 'tns-core-modules/ui/core/view-base'.
[20-05-06 11:10:12.631] (CLI) ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts
[20-05-06 11:10:12.631] (CLI) [tsl] ERROR in C:\NativeScript\nativescript-barcodescanner-master\src\barcodescanner-common.ts(199,42)
[20-05-06 11:10:12.631] (CLI) TS2354: This syntax requires an imported helper but module 'tslib' cannot be found.
[20-05-06 11:10:13.831] Build failed. Executing webpack failed with exit code 2.
Я хотел бы, чтобы кто-нибудь объяснил мне, как использовать плагин, иначе, если у кого-то есть пример, который может мне помочь, иначе, если они знают другой плагин, который проще в использовании.