Last active
April 7, 2021 13:01
-
-
Save Fanna1119/2fbb07431f86ce8a6b4ac6217d84ebe5 to your computer and use it in GitHub Desktop.
pinia store
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
import { defineStore } from 'pinia' | |
export const useMainStore = defineStore({ | |
id: 'main', | |
state: () => ({ | |
todos: [], | |
}), | |
getters: { | |
getAllTodos() { | |
return this.todos | |
}, | |
todoEmpty() { | |
return this.todos.length <= 0 | |
} | |
}, | |
actions: { | |
addTodo(todo) { | |
this.todos.push(todo); | |
}, | |
removeTodo(index) { | |
this.todos.splice(index, 1) | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment