Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call mutations in vuex

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report