Skip to content

[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

Open
haizhilin2013 opened this issue Jul 2, 2019 · 6 comments
Open

[vue] vuex中actions和mutations有什么区别? #537

haizhilin2013 opened this issue Jul 2, 2019 · 6 comments
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] vuex中actions和mutations有什么区别?

@haizhilin2013 haizhilin2013 added the vue vue label Jul 2, 2019
@zyronon
Copy link

zyronon commented Jul 2, 2019

actions可以异步,mutations不可以

@joyeeLee
Copy link

actions是异步处理state,mutations是同步处理state,这样说对吗

@zejunking
Copy link

zejunking commented Aug 20, 2019

mutations可以直接修改state,但只能包含同步操作,同时,只能通过提交commit调用(尽量通过Action或mapMutation调用而非直接在组件中通过this.$store.commit()提交)
actions是用来触发mutations的,它无法直接改变state,它可以包含异步操作,它只能通过store.dispatch触发

@liuxiaoyang1
Copy link

mutations 是同步的,直接操作,提交commit就可以了,而actions 是异步的操作,比如axios 请求后台数据

@cherry728
Copy link

action是异步的更改state,本质是dispatch一个action,在action里面其实也是commit一个mutation的。mutation里面是直接对state进行更改

@crush2020
Copy link

actions:主要用来处理异步,提交的是mutations,在组件中用dispatch()派发
mutations:用来直接修改state的在组件中用this.$store.commit()触发
其两个都可以用辅助函数mapActions
详细参考地址:https://vuex.vuejs.org/zh/guide/actions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

7 participants