Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

vuex action 是全局事件触发的执行函数,
定义

1
2
3
4
5
6
7
8
9
10
11
12
const actions  = {
login(state) {
axios('login').then(res ={
state.login = true
})
}
}

// 执行
this.dispatch("login").then(res => {

})

相交于一般 muitition具有异步执行的功能😺,
具体是包了一层Promise.resolve,其实完全可以用muitition,commit实现,只要return new Promise

1
2
3
4
5
6
7
8
9
10
11
12
const mutations = {
login (state) {
return new Promise(resolve => {
axios('login').then(res ={
resolve(res)
state.login = true
})
})
}
}
// 执行
this.$store.commit("login").then(res => {})

评论