1. Auxiliary functions When a component needs to obtain multiple states, declaring all of these states as calculated properties will be somewhat repetitive and redundant. To solve this problem, we can use the Introduce auxiliary functions into script: import { mapState, mapMutations, mapActions, mapGetters } from 'vuex' 2. Examples1. mapState and mapGetters Because For example: Now there is a property userName in the store state: In the Home.vue component, it is obtained through mapState and displayed on the interface: Code in computed: computed:{ //Get the state in the store through the auxiliary function ...mapState(['userName']) //Equivalent to: the following regular calculated property code /* userName (){ return this.$store.state.userName }*/ } Calling in the page: result: In this way, you can use a simple 2. mapMutations and mapActions Because For example: Now in The code in methods:{ //Abbreviation for getting mutations in the store ...mapMutations(['tip']) //Equivalent to /* tip(){ this.$store.commit('tip'); }*/ } Call in component: Call the tip method in the The use of As you can see from the above example, the benefit of auxiliary functions is that they help us simplify getting the state, getter, mutation, and action in the store. Of course, the above functions can be achieved without using auxiliary functions, but when multiple states need to be used simultaneously in a component, auxiliary functions become more convenient. This concludes this article about the four auxiliary functions of Vuex of Vue. For more relevant Vuex auxiliary function content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Detailed explanation of command to view log files in Linux environment
This article mainly introduces the ::master pseud...
HTML provides five space entities with different ...
Environment Preparation 1. Environment Constructi...
MySQL installation tutorial for Windows system do...
If a website is widescreen, you drag the browser ...
1. Common connections for mysql INNER JOIN (inner...
Log in to your account export DOCKER_REGISTRY=reg...
Preface I need to add a synchronized scrolling fe...
In the past few years, DIV+CSS was very popular in...
This article example shares the specific code of ...
With the development of Internet technology, user...
mysql between boundary range The range of between...
Table of contents Preface Environment Preparation...
CHAR and VARCHAR types are similar, differing pri...
Table of contents Why use gzip compression? nginx...