Home > Web Front-end > JS Tutorial > body text

Detailed explanation of vuex using object expansion operator instance

小云云
Release: 2018-05-12 11:20:53
Original
1882 people have browsed it

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
Copy after login

2. You need to add the following in the .babelrc file

{

 "presets": [

  ["env", { "modules": false }]

 ],

 "plugins": ["transform-object-rest-spread"] //增加这一行

}
Copy after login

3. Use

<script>

  import {mapState,mapGetters} from &#39;vuex&#39;

  export default {

    methods:{

      increment(){

        this.$store.commit(&#39;increment&#39;);

      }

    },

    computed:{

      ...mapGetters([

        &#39;count&#39;

      ]),

      ...mapState({

        counts(){

          return this.$store.state.count;

        }

      })

    }

  }

</script>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!