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

Detailed explanation of how to use object expansion operator instances in vuex

小云云
Release: 2018-02-01 13:22:52
Original
2618 people have browsed it

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
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 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!

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!