iview / iview/iview-admin

报错:Cannot read property 'avator' of undefined

Open
#949 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vue
Stars
16.3k
Forks
4.7k
PR merge metrics
No merged PRs in 30d

Description

npm run dev 打开页面后加载不出来,控制台显示js 报错:Cannot read property 'avator' of undefined
at eval (user.js?7fa2:68)

代码在 store/module/user.js 文件里:
```
// 获取用户相关信息
getUserInfo ({ state, commit }) {
return new Promise((resolve, reject) => {
getUserInfo(state.token).then(res => {
const data = res.data
commit('setAvator', data.avator)
commit('setUserName', data.user_name)
commit('setUserId', data.user_id)
commit('setAccess', data.access)
resolve(data)
}).catch(err => {
reject(err)
})
})
}
```

data 返回是 undefined,默认请求的数据源是哪里的?是不是要改?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running npm run dev and inspect store/module/user.js, especially getUserInfo and the request that supplies res.data. Trace the default data source and verify why it returns undefined before the avatar access. Done means the page loads without the reported JavaScript error and the user data fields are available.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.