Skip to content

Instantly share code, notes, and snippets.

@Fanna1119
Last active April 7, 2021 13:01
Show Gist options
  • Save Fanna1119/2fbb07431f86ce8a6b4ac6217d84ebe5 to your computer and use it in GitHub Desktop.
Save Fanna1119/2fbb07431f86ce8a6b4ac6217d84ebe5 to your computer and use it in GitHub Desktop.
pinia store
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