vue login.js登录逻辑

    // 验证码
    changeImg() {
        this.imgurl = '/api/changeCode?' + Math.random()
      },
      login() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.username = this.loginForm.username
            this.password = this.loginForm.password
            this.$http.post('/api/user/frontCheckLogin/' + this.username + '/' + this.password)
              .then(res => {
                // console.log(res.data)
                if (res.data.code == 200) {
                  this.$store.commit('SET_TOKEN', this.loginForm.username)
                  this.$store.commit('GET_USER', this.loginForm)
                  // console.log(this.$store)
                  this.$http.get('/api/perm/2/')
                    .then(res => {
                      this.$store.commit('BTNS', res.data.data)
                    })
                  this.getSelection()
                  this.$message({
                    message: '登陆成功',
                    type: 'success',
                    customClass: 'zZindex',
                    duration: 1000
                  })
                } else {
                  this.$message({
                    message: res.data.message,
                    type: 'error',
                    customClass: 'zZindex'
                  })
                }
              })
              .catch(err => {
                console.log(err)
              })
          } else {
            console.log("error submit!!")
            return false
          }
        })
      }
posted @ 2019-08-18 23:46  叶子玉  阅读(1643)  评论(0编辑  收藏  举报