Home >Web Front-end >JS Tutorial >Detailed explanation of how to use object expansion operator instances in vuex
When vuex needs to be used for data state management, mapGetters, mapState, and its own calculated properties will be used. This will be used at this time! This article mainly introduces to you examples of using the object expansion operator in vuex. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
1. First you need to install
npm install babel-plugin-transform-object-rest-spread -D
2. You need to add the following
{ "presets": [ ["env", { "modules": false }] ], "plugins": ["transform-object-rest-spread"] //增加这一行 }
3. Use
<script> import {mapState,mapGetters} from 'vuex' export default { methods:{ increment(){ this.$store.commit('increment'); } }, computed:{ ...mapGetters([ 'count' ]), ...mapState({ counts(){ return this.$store.state.count; } }) } } </script>
in vue components. Related recommendations:
Operator rules and implicits in JavaScript Detailed explanation of type conversion examples
Summary of operators and functions in Mysql
Detailed introduction to operator rules and implicit type conversions in JavaScript
The above is the detailed content of Detailed explanation of how to use object expansion operator instances in vuex. For more information, please follow other related articles on the PHP Chinese website!