Home >Web Front-end >JS Tutorial >Detailed explanation of how to use object expansion operator instances in vuex

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

小云云
小云云Original
2018-02-01 13:22:522670browse

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


in the .babelrc file.
{

 "presets": [

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

 ],

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

}

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>

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!

Statement:
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