Files
maaw/pages/dashboard.vue
Michael Dausmann 8b2348f6a3 add/delete notes
2023-04-14 00:24:22 +10:00

28 lines
753 B
Vue

<script setup lang="ts">
import { storeToRefs } from 'pinia';
definePageMeta({
middleware: ['auth'],
});
const notesStore = useNotesStore();
const { notes } = storeToRefs(notesStore); // ensure the notes list is reactive
const newNoteText = ref('')
async function addNote(){
await notesStore.createNote(newNoteText.value)
newNoteText.value = '';
}
onMounted(async () => {
await notesStore.fetchNotesForCurrentUser();
});
</script>
<template>
<div>
<h3>Notes Dashboard</h3>
<p v-for="note in notes">{{ note.note_text }} <button @click.prevent="notesStore.deleteNote(note.id)">-</button></p>
<p><input v-model="newNoteText"/><button @click.prevent="addNote()">Add</button></p>
</div>
</template>