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 23:24:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
002406fc314b9ae581ed58c6c66d7a13fc2f3d20
002406fc
1 parent
ad641a73
mapState 工具功能添加
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
src/App.vue
src/components/counter.vue
src/App.vue
View file @
002406f
...
...
@@ -30,9 +30,6 @@ export default {
}
},
computed: {
count() {
return this.$store.state.count
},
isLogin() {
return this.$store.state.isLogin
}
...
...
src/components/counter.vue
View file @
002406f
<template lang="html">
<div>{{ count }}</div>
<div>
count: {{ count }}
countPlusLocalState: {{countPlusLocalState}}
</div>
</template>
<script>
import {
mapState
} from 'vuex'
export default {
data () {
return {}
},
computed: {
count () {
return this.$store.state.count
}
},
mounted () {},
methods: {},
components: {}
data() {
return {
localCount: 10
}
},
computed: mapState({
// 箭头函数可以让代码非常简洁
count: state => state.count,
// 传入字符串 'count' 等同于 `state => state.count`
countAlias: 'count',
// 想访问局部状态,就必须借助于一个普通函数,函数中使用 `this` 获取局部状态
countPlusLocalState (state) {
return state.count + this.localCount
}
}),
mounted() {},
methods: {},
components: {}
}
</script>
...
...
Please
register
or
login
to post a comment