|
@@ -70,6 +70,9 @@ export default {
|
|
// arrow functions can make the code very succinct!
|
|
// arrow functions can make the code very succinct!
|
|
count: state => state.count,
|
|
count: state => state.count,
|
|
|
|
|
|
|
|
+ // passing the string value 'count' is same as `state => state.count`
|
|
|
|
+ countAlias: 'count',
|
|
|
|
+
|
|
// to access local state with `this`, a normal function must be used
|
|
// to access local state with `this`, a normal function must be used
|
|
countPlusLocalState (state) {
|
|
countPlusLocalState (state) {
|
|
return state.count + this.localCount
|
|
return state.count + this.localCount
|
|
@@ -78,6 +81,15 @@ export default {
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+We can also pass a string array to `mapState` when the name of mapped computed property is same as state sub tree name.
|
|
|
|
+
|
|
|
|
+``` js
|
|
|
|
+computed: mapState([
|
|
|
|
+ // map this.count to store.state.count
|
|
|
|
+ 'count'
|
|
|
|
+])
|
|
|
|
+```
|
|
|
|
+
|
|
### Object Spread Operator
|
|
### Object Spread Operator
|
|
|
|
|
|
Note that `mapState` returns an object. How do we use it in combination with other local computed properties? Normally, we'd have to use a utility to merge multiple objects into one so that we can pass the final object to `computed`. However with the [object spread operator](https://github.com/sebmarkbage/ecmascript-rest-spread) (which is a stage-3 ECMASCript proposal), we can greatly simplify the syntax:
|
|
Note that `mapState` returns an object. How do we use it in combination with other local computed properties? Normally, we'd have to use a utility to merge multiple objects into one so that we can pass the final object to `computed`. However with the [object spread operator](https://github.com/sebmarkbage/ecmascript-rest-spread) (which is a stage-3 ECMASCript proposal), we can greatly simplify the syntax:
|