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

Commit 5263e8e

Browse files
committed
fix首页切换bug
1 parent 2be01ea commit 5263e8e

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ npm run dev
4040
目前已经完成了绝大部分功能,尚未完成的功能在和遇到的问题在todo中
4141

4242
目前存在的问题
43+
4344
~~小程序无法动态插入dom,markdwon的解析有点问题, [wemark](https://github.com/TooBug/wemark)在mpvue上使用需要改造下。已封装[mpvue-wemark](https://github.com/673800357/mpvue-wemark)解决
4445

4546

4647
todo
4748

48-
- 帖子评论、回复功能
4949
- 帖子收藏和取消收藏功能
50-
- 评论点赞和收藏的UI同步
50+
- 评论点赞和收藏的UI同步 // 好像后端有bug
5151
- 帖子详情页加载评论时惰性渲染和回到顶部
5252
- 编辑自己发过的主题
5353
- 展示未读消息数和消息已读
5454
- 部分页面添加下拉刷新
55-
- 主页几个tab切换有点bug
5655
- 请求失败状态码非200会抛异常,如何统一优雅处理
5756
后话:
5857

src/components/sendReply.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export default {
2323
methods: {
2424
prevent() {},
2525
async send() {
26-
console.log(this.content, this.replyId, this.topicId);
2726
const accesstoken = wx.getStorageSync("accesstoken");
2827
try {
2928
const res = await this.$http.post(

src/pages/detail/index.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<wemark :mdData='item.content'></wemark>
3939
</p>
4040
<div class='foot'>
41-
<div :data-replyid='item.id' :data-originindex='originindex' @click.stop="upOrCancel($event)"><img class='icon' v-if='!item.is_uped' src='../../../static/good1.png' /><img class='icon' v-if='item.is_uped' src='../../../static/good2.png' /><span>点赞:{{item.ups.length}}</span></div>
41+
<div :data-replyid='item.id' :data-originindex='originindex' @click.stop="upOrCancel($event)"><img class='icon' :src="(!item.is_uped)?'../../../static/good1.png':'../../../static/good2.png'" /><span>点赞:{{item.ups.length}}</span></div>
4242
<div :data-loginname='item.author.loginname' @click.stop="showReplyModal($event)" :data-replyid='item.id'><img class='icon' src='../../../static/chat.png' /><span>回复</span></div>
4343
</div>
4444
</div>
@@ -104,6 +104,7 @@ export default {
104104
// console.log(e);
105105
const accesstoken = wx.getStorageSync("accesstoken");
106106
if (accesstoken) {
107+
try{
107108
const res = await this.$http.post(
108109
`${api}/reply/${e.currentTarget.dataset.replyid}/ups`,
109110
{
@@ -116,13 +117,17 @@ export default {
116117
icon: "none",
117118
duration: 2000
118119
});
119-
} else {
120+
}
121+
this.getData();
122+
}catch(e){
120123
wx.showToast({
121-
title: res.data.error_msg,
124+
title: e.response.data.error_msg,
122125
icon: "none",
123126
duration: 2000
124127
});
125128
}
129+
130+
126131
// originindex
127132
} else {
128133
wx.showToast({

src/pages/index/index.vue

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<template>
22
<div class='container'>
33
<div class='header'>
4-
<div :class='{ active: tab==="all" }' @click.stop='changeTab($event)' data-tab='all'>全部</div>
4+
<div :class='{ active: tab==="all" }' @click.stop='changeTab($event)' data-tab='all'>全部</div>
55
<div :class='{ active: tab==="good" }' @click.stop='changeTab($event)' data-tab='good'>精华</div>
66
<div :class='{ active: tab==="share" }' @click.stop='changeTab($event)' data-tab='share'>分享</div>
77
<div :class='{ active: tab==="job" }' @click.stop='changeTab($event)' data-tab='job'>招聘</div>
88
<div :class='{ active: tab==="ask" }' @click.stop='changeTab($event)' data-tab='ask'>问答</div>
99
</div>
10-
<scroll-view scroll-y class='scroll-container' @scrolltolower='getMore'>
11-
<div v-for='item in cardData' :key='item.id'>
12-
<card :item='item'></card>
13-
</div>
14-
</scroll-view>
10+
<div v-for='(listItem,listIndex) in list' :key='listIndex' v-show="listItem===tab">
11+
<scroll-view scroll-y class='scroll-container' @scrolltolower='getMore'>
12+
<div v-for='item in cardData[listItem]' :key='item.id'>
13+
<card :item='item'></card>
14+
</div>
15+
</scroll-view>
16+
</div>
1517
</div>
1618
</template>
1719

@@ -24,11 +26,22 @@ export default {
2426
return {
2527
page: 0,
2628
tab: "all",
27-
cardData: [],
28-
isLoading: false
29+
cardData: {
30+
all: [],
31+
good: [],
32+
share: [],
33+
job: [],
34+
ask: []
35+
},
36+
isLoading: false,
37+
list: ["all", "good", "share", "job", "ask"]
38+
// all: [],
39+
// good: [],
40+
// share: [],
41+
// job: [],
42+
// ask: []
2943
};
3044
},
31-
3245
components: {
3346
card
3447
},
@@ -38,7 +51,9 @@ export default {
3851
},
3952
methods: {
4053
async getData(tab, page) {
41-
wx.showLoading({ title: "加载中" });
54+
wx.showLoading({
55+
title: "加载中"
56+
});
4257
this.isLoading = true;
4358
const res = await this.$http.get(`${api}/topics`, {
4459
tab,
@@ -47,14 +62,15 @@ export default {
4762
});
4863
wx.hideLoading();
4964
if (res.data.success) {
50-
if (this.cardData.length > 0 && page === 0) {
65+
if (this.cardData[tab].length > 0 && page === 0) {
5166
// 下拉刷新
52-
console.log("新的", res.data.data, tab);
53-
this.cardData = res.data.data;
67+
console.log("新的", res.data.data, tab);
68+
69+
this.cardData[tab] = res.data.data;
5470
// res.data.data;
5571
} else {
5672
// 底部加载更多 h和初始得时候
57-
this.cardData = [...this.cardData, ...res.data.data];
73+
this.cardData[tab] = [...this.cardData[tab], ...res.data.data];
5874
}
5975
} else {
6076
// 获取数据失败

0 commit comments

Comments
 (0)