```
index.js文件
actions :{
[ADD](context, payload){
console.log(context, payload);
return new Promise((resolve, reject)=>{
setTimeout(()=>{
context.commit(ADD, 'payload');
resolve('success')
},1500)
})
}
}
```
```
xx.vue文件
methods :{
addFn(num){
this.$store.dispatch(ADD, num)
.then((result)=>{
console.log(result)
}).catch((err)=>{
console.log(err)
})
}
}
```
```
actions :{
[ADD](context, payload){
console.log(context, payload);
return new Promise((resolve, reject)=>{
axios.get('/',{params:{a : 1}})
.then(res=>{
if(res.code === 0){
resolve('success')
}else{
reject('lose')
}
}).catch(err=>{
console.log(err);
})
})
}
}
```