From 4576b66f67737cbc7b39296229a58daa6a6896a2 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 4 Sep 2021 14:13:53 +0200 Subject: [PATCH] rewrite the watcher to only watch the remainingFunds object --- .../src/App.vue | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/2021-09-04_composition-assignment-2-problem/src/App.vue b/2021-09-04_composition-assignment-2-problem/src/App.vue index 9b2410e..a012110 100644 --- a/2021-09-04_composition-assignment-2-problem/src/App.vue +++ b/2021-09-04_composition-assignment-2-problem/src/App.vue @@ -40,11 +40,14 @@ export default { data.currentExpenses += enteredExpense.value; } - watch(data, function(_, newValue) { - if (newValue.remainingFunds < 0) { - alert('You are broke!'); + watch( + () => data.remainingFunds, + function(_, newValue) { + if (newValue < 0) { + alert('You are broke!'); + } } - }); + ); return { data,