-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] vuex中actions和mutations有什么区别? #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
actions可以异步,mutations不可以 |
actions是异步处理state,mutations是同步处理state,这样说对吗 |
mutations可以直接修改state,但只能包含同步操作,同时,只能通过提交commit调用(尽量通过Action或mapMutation调用而非直接在组件中通过this.$store.commit()提交) |
mutations 是同步的,直接操作,提交commit就可以了,而actions 是异步的操作,比如axios 请求后台数据 |
action是异步的更改state,本质是dispatch一个action,在action里面其实也是commit一个mutation的。mutation里面是直接对state进行更改 |
actions:主要用来处理异步,提交的是mutations,在组件中用dispatch()派发 |
[vue] vuex中actions和mutations有什么区别?
The text was updated successfully, but these errors were encountered: