Home > Article > Web Front-end > Detailed explanation of vuex using object expansion operator instance
Usage scenarios
When vuex needs to be used for data state management, mapGetters, mapState, and its own calculated properties will be used. This is it! 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 in the .babelrc file
{ "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 the vue component
Related recommendations:
Detailed explanation of operator rules and implicit type conversion examples in JavaScript
php ternary operator and if Detailed explanation
Introduction to the use of operators in PHP development
The above is the detailed content of Detailed explanation of vuex using object expansion operator instance. For more information, please follow other related articles on the PHP Chinese website!