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 {
-
+