How to call mutations in vuex
This article mainly introduces how to call mutations in vuex, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
The calling method of mutations is called directly through the $store.commit call.
No other configuration is required
Introduce mapMutationsimport {mapMutations} from 'vuex'export default {data () {return {msg: "hello vuex"}}, / / register methods by registering method calls in methods. Is a property expander, you can expand the method in mapMutations and put it in methods, and you can directly call methods: {. MapMutations (['method name in mutations'])}}-Why should you use mutations in the use of fine mutations?
The advantage of using mutations is that you can track where the method in mutations is called, and calling mutations in strict mode will not report an error.
Neither of the benefits mentioned above exists in any other way.
Usage
First define a mutations object, and then define the specified method, very simple, code example:
State: {isHome: true}, mutations: {changeIsHome (state) {/ / here state is passed in state.isHome = false}}
After defining the mutations method in stote.js, you can call the mutations method when the event is triggered in vue. Call the method example:
/ / the example here is to trigger the mutations method created () {this.$store.commit ('changeIsHome') / / this is the method called in the created method.
Execute: this.$store.commit ('changeIsHome'); and you can call the mutations method.
The above is all the contents of the article "how to call mutations in vuex". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!