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-29 22:40:46 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8c6bd349b640c25f34369324a6cb81d0c028ec51
8c6bd349
1 parent
71da455f
getters 函数
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
9 deletions
src/App.vue
src/components/getters.vue
src/main.js
src/App.vue
View file @
8c6bd34
...
...
@@ -12,6 +12,7 @@
<child :level="1">Hello world!</child>
<child :level="3">Hello world!</child>
<my-paragraph></my-paragraph>
<getters></getters>
</div>
</template>
...
...
@@ -19,8 +20,7 @@
import counter from './components/counter.vue'
import child from './components/child.vue'
import myParagraph from './components/myParagraph.vue'
import { store } from './main.js'
import getters from './components/getters.vue'
export default {
name: 'app',
...
...
@@ -31,25 +31,25 @@ export default {
},
computed: {
count() {
return store.state.count
return
this.$
store.state.count
},
isLogin() {
return store.state.isLogin
return
this.$
store.state.isLogin
}
},
methods: {
increment() {
store.commit('increment')
this.$
store.commit('increment')
},
decrement() {
store.commit('decrement')
this.$
store.commit('decrement')
},
login() {
store.commit('login')
this.$
store.commit('login')
}
},
components: {
counter,child,myParagraph
counter,child,myParagraph
,getters
}
}
</script>
...
...
src/components/getters.vue
0 → 100644
View file @
8c6bd34
<template lang="html">
<div>
doneTodos: {{doneTodos}}
</div>
</template>
<script>
export default {
data () {
return {}
},
computed: {
doneTodos (){
return this.$store.getters.doneTodos
}
},
mounted () {},
methods: {},
components: {}
}
</script>
<style lang="css">
</style>
src/main.js
View file @
8c6bd34
...
...
@@ -8,7 +8,16 @@ const store = new Vuex.Store({
state
:
{
count
:
0
,
size
:
10
,
isLogin
:
false
isLogin
:
false
,
todos
:
[
{
id
:
1
,
text
:
'...'
,
done
:
true
},
{
id
:
2
,
text
:
'...'
,
done
:
false
}
]
},
getters
:
{
doneTodos
:
state
=>
{
return
state
.
todos
.
filter
(
todo
=>
todo
.
done
)
}
},
mutations
:
{
increment
:
state
=>
state
.
count
++
,
...
...
Please
register
or
login
to post a comment