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 00:34:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
99b40f6c106473c15c1ea14eddfe2602a6ba5d1f
99b40f6c
1 parent
002406fc
add mutations
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
8 deletions
src/App.vue
src/store.js
src/App.vue
View file @
99b40f6
...
...
@@ -5,7 +5,8 @@
{{isLogin}}
</div>
<p>
<button @click="increment">+</button>
<!-- <button @click="increment">+</button> -->
<button @click="add">add</button>
<button @click="decrement">-</button>
<button @click="login">login</button>
</p>
...
...
@@ -13,6 +14,8 @@
<child :level="3">Hello world!</child>
<my-paragraph></my-paragraph>
<getters></getters>
<span>obj: {{obj}}</span>
<button @click="addObj">addObj</button>
</div>
</template>
...
...
@@ -21,6 +24,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 { mapMutations } from 'vuex'
export default {
name: 'app',
...
...
@@ -32,21 +36,46 @@ export default {
computed: {
isLogin() {
return this.$store.state.isLogin
},
obj () {
return this.$store.state.obj
}
},
methods: {
increment() {
this.$store.commit('increment')
},
// increment() {
// this.$store.commit('increment', {
// amount: 10
// })
// // this.$store.commit('increment', {
// // amount: 10
// // },{silent:true})
// // this.$store.commit({
// // type:'increment',
// // amount: 10
// // })
// },
decrement() {
this.$store.commit('decrement')
},
login() {
this.$store.commit('login')
}
},
addObj() {
this.$store.commit('addObj')
},
...mapMutations({
add: 'increment' // 映射 this.add() 到 this.$store.commit('increment')
})
// ...mapMutations([
// 'increment' // 映射 this.increment() 到 this.$store.commit('increment')
// ]),
},
components: {
counter,child,myParagraph,getters
counter,
child,
myParagraph,
getters
}
}
</script>
...
...
src/store.js
View file @
99b40f6
...
...
@@ -16,7 +16,10 @@ const store = new Vuex.Store({
id
:
2
,
text
:
'...'
,
done
:
false
}]
}],
obj
:
{
size
:
1
}
},
getters
:
{
doneTodos
:
state
=>
{
...
...
@@ -27,9 +30,13 @@ const store = new Vuex.Store({
}
},
mutations
:
{
// increment (state, payload) {
// state.count += payload.amount
// },
increment
:
state
=>
state
.
count
++
,
decrement
:
state
=>
state
.
count
--
,
login
:
state
=>
state
.
isLogin
=
true
login
:
state
=>
state
.
isLogin
=
true
,
addObj
:
state
=>
state
.
obj
=
{
...
state
.
obj
,
newProp
:
123
}
}
})
...
...
Please
register
or
login
to post a comment