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-30 16:19:31 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
63e6af9f56cb69badc46d3b47f28831240bd993a
63e6af9f
1 parent
99b40f6c
add module
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
4 deletions
src/App.vue
src/components/module.vue
src/store.js
src/App.vue
View file @
63e6af9
...
...
@@ -9,6 +9,7 @@
<button @click="add">add</button>
<button @click="decrement">-</button>
<button @click="login">login</button>
<button @click="incrementAsync">incrementAsync</button>
</p>
<child :level="1">Hello world!</child>
<child :level="3">Hello world!</child>
...
...
@@ -16,6 +17,7 @@
<getters></getters>
<span>obj: {{obj}}</span>
<button @click="addObj">addObj</button>
<module></module>
</div>
</template>
...
...
@@ -24,6 +26,7 @@ import counter from './components/counter.vue'
import child from './components/child.vue'
import myParagraph from './components/myParagraph.vue'
import getters from './components/getters.vue'
import module from './components/module.vue'
import { mapMutations } from 'vuex'
export default {
...
...
@@ -65,17 +68,20 @@ export default {
},
...mapMutations({
add: 'increment' // 映射 this.add() 到 this.$store.commit('increment')
})
})
,
// ...mapMutations([
// 'increment' // 映射 this.increment() 到 this.$store.commit('increment')
// ]),
incrementAsync() {
this.$store.dispatch('incrementAsync')
}
},
components: {
counter,
child,
myParagraph,
getters
getters,
module
}
}
</script>
...
...
src/components/module.vue
0 → 100644
View file @
63e6af9
<template lang="html">
<div>
moduleA: {{moduleA}}
moduleB: {{moduleB}}
</div>
</template>
<script>
export default {
computed: {
moduleA(){
return this.$store.state.a.module
},
moduleB(){
return this.$store.state.b.module
}
}
}
</script>
<style lang="css">
</style>
src/store.js
View file @
63e6af9
...
...
@@ -3,6 +3,24 @@ import Vuex from 'vuex'
Vue
.
use
(
Vuex
)
const
moduleA
=
{
state
:
{
module
:
'A'
},
getters
:
{},
mutations
:
{},
actions
:
{}
}
const
moduleB
=
{
state
:
{
module
:
'B'
},
getters
:
{},
mutations
:
{},
actions
:
{}
}
const
store
=
new
Vuex
.
Store
({
state
:
{
count
:
0
,
...
...
@@ -36,7 +54,24 @@ const store = new Vuex.Store({
increment
:
state
=>
state
.
count
++
,
decrement
:
state
=>
state
.
count
--
,
login
:
state
=>
state
.
isLogin
=
true
,
addObj
:
state
=>
state
.
obj
=
{
...
state
.
obj
,
newProp
:
123
}
addObj
:
state
=>
state
.
obj
=
{...
state
.
obj
,
newProp
:
123
}
},
actions
:
{
increment
({
commit
})
{
// 对象解构
commit
(
'increment'
)
},
incrementAsync
({
commit
})
{
setTimeout
(()
=>
{
commit
(
'increment'
)
},
1000
)
}
},
modules
:
{
a
:
moduleA
,
b
:
moduleB
}
})
...
...
Please
register
or
login
to post a comment