当前位置 博文首页 > 你是人间四月天:element admin登录后跳转失败

    你是人间四月天:element admin登录后跳转失败

    作者:[db:作者] 时间:2021-09-05 13:07

    在src\store\modules\user.js中需要把getinfo注释掉

      getInfo({ commit, state }) {
        return new Promise((resolve, reject) => {
          //此方法是login登陆成功后执行用写死的数据代替返回值,注意框架结构!
          // getInfo(state.token).then(response => {
            const  data  = {
              roles: ['admin'],
              introduction: 'I am a super administrator',
              avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
              name: 'Super Admin'
            }
    
            if (!data) {
              reject('Verification failed, please Login again.')
            }
    
            const { roles, name, avatar, introduction } = data
    
            // roles must be a non-empty array
            if (!roles || roles.length <= 0) {
              reject('getInfo: roles must be a non-null array!')
            }
    
            commit('SET_ROLES', roles)
            commit('SET_NAME', name)
            commit('SET_AVATAR', avatar)
            commit('SET_INTRODUCTION', introduction)
            resolve(data)
          // }).catch(error => {
          //   reject(error)
          // })
        })
      },
    

    在src\api\user.js中的login接口

    //登录
    //userName 用户名
    //password 密码
    export function login(data) {
      console.log(data)
      return request({
        url: '/login', //注意请求方式及路径
        method: 'post', 
        data
      })
    }
    

    在.env.development文件中配置好BASE_API
    VUE_APP_BASE_API = ‘http://www.zhangsan.com/api’

    在src\utils\request.js中根据自己的实际code写入判断

    在这里插入图片描述
    再次登录就可以跳转到首页了 ,后面可以把写死的数据换成自己真实数据。

    cs