Skip to content

Commit 08cf21a

Browse files
committed
fix todo example
1 parent 6bb878e commit 08cf21a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

example/src/components/views/todo/todo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default class Todo extends Vue {
3131
@module.Getter(types.getter.filterTodos) todos
3232

3333
@module.Mutation(types.mutation.setFilter) setFilter
34+
@module.Mutation(types.mutation.clearData) clearData
3435

3536
@module.Action(types.action.fetch) fetch
3637
@module.Action(types.action.save) save
@@ -49,4 +50,9 @@ export default class Todo extends Vue {
4950
this.setFilter(this.$route.params.filter)
5051
}
5152
}
53+
54+
beforeDestroy () {
55+
// 理论上是要清除掉大数据,但是这里 filter 使用链接的方式,所以不需要清掉
56+
// this.clearData()
57+
}
5258
}

example/src/store/modules/todo.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ let mutations = mutation(state, {
7777

7878
clearComplete (state) {
7979
state.todos = state.todos.filter(v => !v.completed)
80+
},
81+
82+
clearData () {
83+
// 将大数据重置,以免一直存在内存
84+
state.todos = []
8085
}
8186
})
8287

0 commit comments

Comments
 (0)