Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
demo-vue-vuex
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Hooke
2016-10-31 13:54:44 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7623baf2a55025f19bbaa7af990dc637156c8903
7623baf2
1 parent
63e6af9f
no message
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
7 deletions
src/components/counter.vue
src/components/getters.vue
src/store.js
src/types.js
src/components/counter.vue
View file @
7623baf
<template lang="html">
<div>
count: {{ count }}
countPlusLocalState: {{countPlusLocalState}}
count: {{ count }} <br />
countAlias: {{ countAlias }} <br />
countPlusLocalState: {{countPlusLocalState}} <br />
localComputed: {{localComputed}}
</div>
</template>
...
...
@@ -16,16 +18,21 @@ export default {
localCount: 10
}
},
computed: mapState({
computed: {
localComputed() {
return 'localComputed'
},
...mapState({
// 箭头函数可以让代码非常简洁
count: state => state.count,
// 传入字符串 'count' 等同于 `state => state.count`
countAlias: 'count',
// 想访问局部状态,就必须借助于一个普通函数,函数中使用 `this` 获取局部状态
countPlusLocalState
(state) {
countPlusLocalState
(state) {
return state.count + this.localCount
}
}),
})
},
mounted() {},
methods: {},
components: {}
...
...
src/components/getters.vue
View file @
7623baf
<template lang="html">
<div>
doneTodos: {{doneTodos}}
doneTodos: {{doneTodos}}
<br />
doneTodosCount: {{doneTodosCount}}
</div>
</template>
...
...
src/store.js
View file @
7623baf
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
*
as
types
from
'./types'
Vue
.
use
(
Vuex
)
...
...
@@ -40,7 +41,7 @@ const store = new Vuex.Store({
}
},
getters
:
{
doneTodos
:
state
=>
{
[
types
.
DONE_TODOS
](
state
)
{
return
state
.
todos
.
filter
(
todo
=>
todo
.
done
)
},
doneTodosCount
:
(
state
,
getters
)
=>
{
...
...
src/types.js
0 → 100644
View file @
7623baf
export
const
DONE_COUNT
=
'todos/DONE_COUNT'
export
const
FETCH_ALL
=
'todos/FETCH_ALL'
export
const
TOGGLE_DONE
=
'todos/TOGGLE_DONE'
export
const
DONE_TODOS
=
'doneTodos'
Please
register
or
login
to post a comment