//登录 this.$store.dispatch("Login", this.loginForm).then(info => { this.loginloading = false; return new Promise((resolve, reject) => { //登录成功后获取token
GetAssessTokenInfo(name, psd)
.then(response => {
resolve(response);
})
.catch(error => {
reject(error);
});
});
})
.catch(() => {
});我想在登录成功后的回调里,发送获取token的协议,正确的promise写法该怎么写?
1 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
store.js
import { login } from '@/api/user' const user = { state: { token: '' }, mutations: { SET_TOKEN: (state, data) => { state.token= data } }, actions: { Login({ commit }, userInfo) { return new Promise((resolve, reject) => { login(userInfo) .then(response => { const data = response.data commit('SET_TOKEN', data.token) resolve(response ) }) .catch(error => { reject(error) }) }) }, // 前端 登出 清除本地token 不访问接口 FedLogOut({ commit }) { return new Promise(resolve => { commit('SET_TOKEN', '') resolve() }) } } }export default user
调用
this.$store.dispatch("Login", this.loginForm).then(info => { // 你的代码 }).catch(err=>{});
添加回答
举报
0/150
提交
取消