Skip to content
This repository was archived by the owner on Jul 9, 2021. It is now read-only.

Commit 8cbb274

Browse files
committed
fix feature.
1 parent 736db41 commit 8cbb274

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

assets/HomePage.png

-23.4 KB
Loading

assets/Loading.png

11.3 KB
Loading

assets/Topics.png

5.7 KB
Loading

assets/UserHome.png

52.8 KB
Loading

src/containers/HomePage.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class HomePage extends Component {
4343
.then(response => response.json())
4444
.then(json => {
4545
if (json.data.length === 0) {
46-
console.log(
47-
'别刷啦,😭已经没有更多帖子惹~~~共计581页(本项目创建之时)'
48-
);
46+
console.log('over');
4947
}
5048
this.setState(prevState => {
5149
return {
@@ -57,22 +55,19 @@ class HomePage extends Component {
5755
});
5856
}
5957
};
60-
componentWillReceiveProps(nextProps, nextState) {
58+
componentWillReceiveProps(nextProps) {
59+
//切换tab后抓取新数据
6160
this.setState({ status: false });
62-
}
63-
componentWillUpdate(nextProps, nextState) {
64-
if (nextProps.location.search !== this.props.location.search) {
65-
fetch(
66-
`https://cnodejs.org/api/v1/topics?tab=${nextProps.location.search.slice(
67-
5
68-
)}`
69-
)
70-
.then(response => response.json())
71-
.then(json => {
72-
this.scroll.scrollTop = 0;
73-
this.setState({ contents: json.data, status: true });
74-
});
75-
}
61+
fetch(
62+
`https://cnodejs.org/api/v1/topics?tab=${nextProps.location.search.slice(
63+
5
64+
)}`
65+
)
66+
.then(response => response.json())
67+
.then(json => {
68+
this.scroll.scrollTop = 0;
69+
this.setState({ contents: json.data, status: true });
70+
});
7671
}
7772
render() {
7873
const wait = '正在加载中···';

src/containers/User.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ class User extends Component {
1111
fetch(`https://cnodejs.org/api/v1/${this.props.location.pathname}`)
1212
.then(res => res.json())
1313
.then(json => {
14-
console.log(json);
1514
this.setState({ data: json });
1615
});
1716
}
1817

1918
render() {
2019
const allData = this.state.data.data;
2120
return (
22-
<div>
21+
<>
2322
{this.state.data ? (
24-
<div>
23+
<div className="user">
2524
<img src={allData.avatar_url} alt={allData.loginname} />
26-
<span>用户名:{allData.loginname}</span>
27-
<span>注册时间:{allData.create_at}</span>
25+
<div className="user_details">
26+
<span>用户名:{allData.loginname}</span>
27+
<span>注册时间:{allData.create_at}</span>
28+
</div>
2829
<div>
2930
最近创建的话题:{allData.recent_topics.map((item, index) => (
3031
<div className="recent_replies" key={index}>
@@ -43,7 +44,7 @@ class User extends Component {
4344
) : (
4445
<span />
4546
)}
46-
</div>
47+
</>
4748
);
4849
}
4950
}

0 commit comments

Comments
 (0)