根据 vuex 的 this.$store.dispatch() 返回值 处理逻辑
1. App.vue
-
const ret = await this.$store.dispatch('userLogin', { username: this.curUserName, password: this.curPassword }) if (ret && ret.info) { this.$message.success(ret.info) await this.$store.dispatch('controlLoginDialog', false) } else { this.$message.warning(ret) }
2. vuex/store/action.js
-
async userLogin ({commit}, account) { let userInfo = {} return new Promise((resolve, reject) => { requestUserLogin(account).then(response => { if (response.status === 200) { if (response.data.data) { userInfo = response.data.data userInfo.userName = userInfo.name userInfo.isLogin = true resolve({ info: userInfo.userName + ' 登录成功,欢迎进入百度云智学院实验平台' }) } else if (response.data.fail) { userInfo.userName = '' userInfo.isLogin = false myConsole('response.data.fail') resolve(response.data.fail) } } else { userInfo.userName = '' userInfo.isLogin = false } commit(USER_LOGIN, {userInfo}) }).catch(err => { myConsole(err) reject(err) }) }) },
3.
--------小尾巴
________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...