File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 1
- #基于vue.js重写Cnodejs.org社区的webapp [ 线上访问地址] ( http://shinygang.github.io/cnodevue / )
1
+ #基于vue.js重写Cnodejs.org社区的webapp [ 线上访问地址] ( http://shinygang.coding.me / )
2
2
3
3
## 注意:当前项目代码已经升级到2.0,采用vue-cli构建的2.0版本。1.x代码请看1.x分支。
4
4
Original file line number Diff line number Diff line change 10
10
<section id =" page" >
11
11
<!-- 首页列表 -->
12
12
<ul class =" posts-list" >
13
- <li v-for =" item in topics" >
13
+ <li v-for =" item in topics" :key = " item.id " >
14
14
<router-link :to =" {name:'topic',params:{id:item.id}}" >
15
15
<h3 v-text =" item.title"
16
16
:class =" getTabInfo(item.tab, item.good, item.top, true)"
58
58
return {
59
59
scroll: true ,
60
60
topics: [],
61
+ index: {},
61
62
searchKey: {
62
63
page: 1 ,
63
64
limit: 20 ,
144
145
$ .get (' https://cnodejs.org/api/v1/topics?' + params, (d ) => {
145
146
this .scroll = true ;
146
147
if (d && d .data ) {
147
- this . topics = d .data ;
148
+ d .data . forEach ( this . mergeTopics ) ;
148
149
}
149
150
});
150
151
},
152
+ mergeTopics (topic ) {
153
+ if (typeof this .index [topic .id ] === ' number' ) {
154
+ const topicsIndex = this .index [topic .id ];
155
+ this .topics [topicsIndex] = topic;
156
+ } else {
157
+ this .index [topic .id ] = this .topics .length ;
158
+ this .topics .push (topic);
159
+ }
160
+ },
151
161
// 滚动加载数据
152
162
getScrollData () {
153
163
if (this .scroll ) {
154
164
let totalheight = parseInt ($ (window ).height (), 20 ) + parseInt ($ (window ).scrollTop (), 20 );
155
165
if ($ (document ).height () <= totalheight + 200 ) {
156
166
this .scroll = false ;
157
- this .searchKey .limit += 20 ;
167
+ this .searchKey .page += 1 ;
158
168
this .getTopics ();
159
169
}
160
170
}
166
176
// 如果是当前页面切换分类的情况
167
177
if (to .query && to .query .tab ) {
168
178
this .searchKey .tab = to .query .tab ;
179
+ this .topics = [];
180
+ this .index = {};
169
181
}
170
- this .searchKey .limit = 20 ;
182
+ this .searchKey .page = 1 ;
171
183
this .getTopics ();
172
184
// 隐藏导航栏
173
185
this .$refs .head .show = false ;
178
190
nvTop
179
191
}
180
192
};
181
- </script >
193
+ </script >
You can’t perform that action at this time.
0 commit comments