Abp Vnext3 vue-admin-template(三獲取用戶信息)


因為獲取用戶比較簡單,只需要把用戶名及頭像地址賦值即可(也許理解錯誤,如果發現請告知謝謝),

首先將src\api\usr.js中的url請求地址改為以下代碼

export function getInfo(token) {
  return request({
    url: '/api/abp/application-configuration',
    method: 'get',
    params: { token }
  })
}

再將store\modules\user.js中getinfo方法改為以下代碼

  // get user info
  getInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo(state.token).then(response => {
        const { data } = response

        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)
      })
    })
  },
修改前代碼
  getInfo({ commit, state }) {
    return new Promise((resolve, reject) => {
      getInfo(state.token).then(response => {
        const { data } = response

        if (!data) {
          return reject('Verification failed, please Login again.')
        }

        this.name = data.currentUser.userName
        this.avatar = null

        commit('SET_NAME', this.name)
        commit('SET_AVATAR', this.avatar)
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

登錄測試能正常顯示用戶名,為了能知道當前登錄用戶,我將用戶名顯示到了導航欄

代碼備份

根據https://www.cnblogs.com/flypig666/p/11854538.html增加了一份帶tagsview版本的下載地址


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM