From 287d0aa41df8883d95103ca621e6103e268b9f3e Mon Sep 17 00:00:00 2001 From: snsd0805 Date: Mon, 12 Jun 2023 19:42:20 +0800 Subject: [PATCH] fix: pop out the warning when scanning a undefine product --- src/views/ShopPayView.vue | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/views/ShopPayView.vue b/src/views/ShopPayView.vue index 7a62d4a..32b4307 100644 --- a/src/views/ShopPayView.vue +++ b/src/views/ShopPayView.vue @@ -65,13 +65,18 @@ export default { onScanSuccess(decodedText, decodedResult) { // handle the scanned code as you like, for example: console.log(`Code matched = ${decodedText}`, decodedResult); - var product = this.products[decodedText] - this.productCar.push({ - 'name': product['name'], - 'id': product['id'], - 'price': product['price'], - 'count': 1 - }) + if (decodedText in this.products){ + var product = this.products[decodedText] + this.productCar.push({ + 'name': product['name'], + 'id': product['id'], + 'price': product['price'], + 'count': 1 + }) + } else { + this.msg = "商品列表中沒有這項商品:"+decodedText + this.warningModalStatus = true + } this.scanner.clear() }, scan() { @@ -130,7 +135,7 @@ export default {
-
+