Skip to content

Commit

Permalink
Balance component
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Nov 6, 2023
1 parent 226b5fb commit 8eb873d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<Header />
<div class="container">
<Balance />
<Balance :total="total" />
<IncomeExpenses />
<TransactionList :transactions="transactions" />
<AddTransaction />
Expand All @@ -15,12 +15,19 @@ import IncomeExpenses from './components/IncomeExpenses.vue';
import TransactionList from './components/TransactionList.vue';
import AddTransaction from './components/AddTransaction.vue';
import { ref } from 'vue';
import { ref, computed } from 'vue';
const transactions = ref([
{ id: 1, text: 'Flower', amount: -19.99 },
{ id: 2, text: 'Salary', amount: 299.97 },
{ id: 3, text: 'Book', amount: -10 },
{ id: 4, text: 'Camera', amount: 150 },
]);
// Get total
const total = computed(() => {
return transactions.value.reduce((acc, transaction) => {
return acc + transaction.amount;
}, 0);
});
</script>
13 changes: 12 additions & 1 deletion src/components/Balance.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<template>
<h4>Your Balance</h4>
<h1 id="balance">$0.00</h1>
<h1 id="balance">${{ total }}</h1>
</template>

<script setup>
import { defineProps } from 'vue';
const props = defineProps({
total: {
type: Number,
required: true,
},
});
</script>

0 comments on commit 8eb873d

Please sign in to comment.