Last active
April 7, 2021 13:15
-
-
Save Fanna1119/05ba2a15f8a2395ef97bdb554f9153a2 to your computer and use it in GitHub Desktop.
pinia todo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<input type="text" v-model="mytodo" /> | |
<button @click="AddTodo">Add Todo</button> | |
<div v-if="!isEmpty"> | |
<p v-for="(todo, index) in todos" :key="index"> | |
{{ index }}. {{ todo }} <button @click="removeTodo(index)">delete</button> | |
</p> | |
</div> | |
<div v-else>No todos found</div> | |
</template> | |
<script> | |
import { computed, ref } from "vue"; | |
import { useMainStore } from "./store.js"; | |
export default { | |
setup() { | |
const main = useMainStore(); | |
const mytodo = ref(""); | |
const AddTodo = () => { | |
if (mytodo.value != "") { | |
main.addTodo(mytodo.value); | |
mytodo.value = ""; | |
} | |
}; | |
return { | |
AddTodo, | |
mytodo, | |
todos: computed(() => main.getAllTodos), | |
isEmpty: computed(() => main.todoEmpty), | |
removeTodo: main.removeTodo, | |
}; | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment