Skip to content

Commit

Permalink
Getter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
malagege committed Jun 22, 2021
1 parent 750360b commit 536f50d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main.js
Expand Up @@ -13,13 +13,23 @@ const store = createStore({
getters: {
doneTodos(state){
return state.todos.filter(todo => todo.done)
}
},
getTodoById: (state) => (id) => {
return state.todos.find(todo => todo.id === id)
},
// 上面 function 等於如下
// getTodoById: function(state){
// return function (id){
// return state.todos.find(todo => todo.id === id)
// }
// },
}
})


// 將 store 實例作為插件安裝
// app.use(store)
createApp(App).use(store).mount('#app')
console.log( store.getters.doneTodos[0].id)
console.log(store.getters.doneTodos);


console.log(store.getters.getTodoById(2))

0 comments on commit 536f50d

Please sign in to comment.