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. 

相关文章:

  • 2021-12-17
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2023-01-10
  • 2022-12-23
  • 2023-03-13
  • 2022-12-23
  • 2021-11-09
  • 2021-10-01
  • 2021-11-18
相关资源
相似解决方案