Skip to content

Instantly share code, notes, and snippets.

@Fanna1119
Created April 7, 2021 13:26
Show Gist options
  • Save Fanna1119/e01ff140c56435dc0c3c2695c345b619 to your computer and use it in GitHub Desktop.
Save Fanna1119/e01ff140c56435dc0c3c2695c345b619 to your computer and use it in GitHub Desktop.
store update
import { defineStore } from 'pinia'
import { useStorage } from '@vueuse/core'
export const useMainStore = defineStore({
id: 'main',
state: () => ({
todos: useStorage('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