Skip to content

Commit

Permalink
Local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Nov 6, 2023
1 parent babc9c6 commit 5c7820d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# vue-expense-tracker
# Vue Expense Tracker

This template should help get you started developing with Vue 3 in Vite.
An expense tracker app built with Vue 3 and the composition API.

## Recommended IDE Setup
- Add and remove expenses/income
- Track balance
- Save data to local storage
- [Vue Toastification](https://github.com/Maronato/vue-toastification) for notifications
- `<script setup>` syntax (Vue 3.2+)

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).
<img src="public/screen.png" width="400" />

## Project Setup

Expand Down
Binary file added public/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 19 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ import IncomeExpenses from './components/IncomeExpenses.vue';
import TransactionList from './components/TransactionList.vue';
import AddTransaction from './components/AddTransaction.vue';
import { ref, computed } from 'vue';
import { ref, computed, onMounted } from 'vue';
import { useToast } from 'vue-toastification';
const toast = useToast();
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 },
]);
const transactions = ref([]);
onMounted(() => {
const savedTransactions = JSON.parse(localStorage.getItem('transactions'));
if (savedTransactions) {
transactions.value = savedTransactions;
}
});
// Get total
const total = computed(() => {
Expand Down Expand Up @@ -62,6 +65,8 @@ const handleTransactionSubmitted = (transactionData) => {
amount: transactionData.amount,
});
saveTransactionsToLocalStorage();
toast.success('Transaction added.');
};
Expand All @@ -76,6 +81,13 @@ const handleTransactionDeleted = (id) => {
(transaction) => transaction.id !== id
);
saveTransactionsToLocalStorage();
toast.success('Transaction deleted.');
};
// Save transactions to local storage
const saveTransactionsToLocalStorage = () => {
localStorage.setItem('transactions', JSON.stringify(transactions.value));
};
</script>

0 comments on commit 5c7820d

Please sign in to comment.