diff --git a/src/apis/moment/moment.ts b/src/apis/moment/moment.ts index d93a129b..9aa652c8 100644 --- a/src/apis/moment/moment.ts +++ b/src/apis/moment/moment.ts @@ -72,7 +72,7 @@ export async function getMomentPreviews(req: GetMomentPreviewsReq) { reject(res); } const data = res.data as GetMomentPreviewsResp; - data.moments.forEach((moment) => { + data.moments?.forEach((moment) => { moment.photos[0] += PictureStyle.thumbnail; moment.user.avatarUrl += PictureStyle.thumbnail; }); diff --git a/src/apis/post/post.ts b/src/apis/post/post.ts index 6813088c..5b128ccd 100644 --- a/src/apis/post/post.ts +++ b/src/apis/post/post.ts @@ -31,7 +31,7 @@ export async function getPostPreviews(req: GetPostPreviewsReq) { ...data, posts: [] }; - data.posts.forEach((post) => { + data.posts?.forEach((post) => { if (!post.user) return; if (post.coverUrl) { post.coverUrl += PictureStyle.thumbnail; diff --git a/src/pages/cat/photos.vue b/src/pages/cat/photos.vue index 6b433be4..178f826c 100644 --- a/src/pages/cat/photos.vue +++ b/src/pages/cat/photos.vue @@ -97,10 +97,9 @@ let getCatImageReq = reactive({ let number = 0; const getCatImageHandler = () => { - console.log("here"); if (!noMore.value) getCatImage(getCatImageReq).then((res) => { - for (let i = 0; i < res.images.length; i++) { + for (let i = 0; i < res.images?.length; i++) { let imageUrl = reactive({ id: res.images[i].id, url: res.images[i].url, @@ -118,10 +117,9 @@ const getCatImageHandler = () => { }); imgUrlList.push(imageUrl); } - let arr = Object.keys(res.images); //获取得到的images的长度用以判断是否还有尚未加载的照片 - number += arr.length; - if (number === 0 || imgUrlList[number - 1].id === getCatImageReq.prevId) { + number += res.images?.length; + if (!number || imgUrlList[number - 1].id === getCatImageReq.prevId) { noMore.value = true; } else getCatImageReq.prevId = imgUrlList[number - 1].id; }); diff --git a/src/pages/community/Masonry.vue b/src/pages/community/Masonry.vue index ba297da2..bc798f2d 100644 --- a/src/pages/community/Masonry.vue +++ b/src/pages/community/Masonry.vue @@ -154,7 +154,7 @@ const addBatch = async () => { }); getComments({ scope: "moment", page: 0, id: moments[i].id }).then((res) => { momentData.comments += res.total; - for (let i = 0; i < res.comments.length; i++) { + for (let i = 0; i < res.comments?.length; i++) { // eslint-disable-next-line no-prototype-builtins if (res.comments[i].hasOwnProperty("comments")) momentData.comments += res.comments[i].comments; diff --git a/src/pages/community/MasonryFrame.vue b/src/pages/community/MasonryFrame.vue index 16f722aa..f5c5097f 100644 --- a/src/pages/community/MasonryFrame.vue +++ b/src/pages/community/MasonryFrame.vue @@ -22,17 +22,15 @@ const props = withDefaults(defineProps(), { const page = ref(0); //每往下翻页一次page加1直到没有内容 const isInitialized = ref(false); -const getPreviews = ref<() => Promise>(); -if (props.search === "default") { - getPreviews.value = async () => { - return ( - await getMomentPreviews({ - page: page.value++, - communityId: uni.getStorageSync(StorageKeys.CommunityId) - }) - ).moments; - }; -} else if (props.search === "search") { +const getPreviews = ref<() => Promise>(async () => { + return ( + await getMomentPreviews({ + page: page.value++, + communityId: uni.getStorageSync(StorageKeys.CommunityId) + }) + ).moments; +}); +if (props.search === "search") { getPreviews.value = async () => { return ( await searchMomentPreviews({ diff --git a/src/pages/moment/moment.vue b/src/pages/moment/moment.vue index 5f05267f..aae9d1e8 100644 --- a/src/pages/moment/moment.vue +++ b/src/pages/moment/moment.vue @@ -1,5 +1,5 @@