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.
所有评论(0)