Hooke

no message

#### Distinguish helper
###### *mapState*
> 读取state中的值进行操作, 不对 state本身进行计算.
```javascript
// 单独计算
computed: mapState({
count: state => state.count,
countAlias: 'count', // 别名
countPlusLocalState (state) {
return state.count + this.localCount // 结合本地值进行计算
}
})
// 计算属性名称 === 状态子树名称
computed: mapState([
'count'
])
// 混合计算
computed: {
localComputed () { /* ... */},
...mapState({
count: state => state.count,
countAlias: 'count', // 别名
countPlusLocalState (state) {
return state.count + this.localCount // 结合本地值进行计算
}
})
}
```
###### mapGetters
> 混合计算时:使用*对象扩展操作符*, 名称相同时传入同名数组, 映射不同名称时, 传入对象键值对, 键值对可以操作参考上面示例混合计算.
```javascript
// 混合计算
computed: {
localComputed () { /* ... */},
...mapGetters([
'doneTodosCount',
'anotherGetter'
])
}
// 映射不同名称
mapGetters({
doneCount: 'doneTodosCount'
})
```
##### Mutations
###### Payload
```javascript
mutations: {
increment (state, payload) {
state.count += payload.amount
}
}
```
```javascript
//
store.commit('increment', {
amount: 10
})
// 对象风格
store.commit({
type: 'increment',
amount: 10
})
```
###### mapMutations
```javascript
methods: {
...mapMutations([
'increment' // 映射 this.increment 到 this.$store.commit('increment')
]),
...mapMutations({
add: 'increment' // 映射 this.add 到 this.$store.commit('increment')
})
}
```
###### Const Named Mutation
```javascript
// mutation-types.js
export const SOME_MUTATION = 'SOME_MUTATION'
```
```javascript
// store.js
import { SOME_MUTATION } from './mutation-types'
mutations: {
[SOME_MUTATION] (state) {
// change state
}
}
```
......@@ -8,9 +8,7 @@
</template>
<script>
import {
mapState
} from 'vuex'
import { mapState } from 'vuex'
export default {
data() {
......