|
@@ -44,8 +44,12 @@ const user = {
|
44
|
44
|
GetInfo({ commit, state }) {
|
45
|
45
|
return new Promise((resolve, reject) => {
|
46
|
46
|
getInfo(state.token).then(response => {
|
47
|
|
- const data = response.data
|
48
|
|
- commit('SET_ROLES', data.roles)
|
|
47
|
+ const data = response
|
|
48
|
+ if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
|
|
49
|
+ commit('SET_ROLES', data.roles)
|
|
50
|
+ } else {
|
|
51
|
+ reject('getInfo: roles must be a non-null array !')
|
|
52
|
+ }
|
49
|
53
|
commit('SET_NAME', data.name)
|
50
|
54
|
commit('SET_AVATAR', data.avatar)
|
51
|
55
|
resolve(response)
|