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版本的下载地址
本文来自博客园,作者:liessay,转载请注明原文链接:https://www.cnblogs.com/liessay/p/13245718.html