From d24b5efcb72a0041c17f45edaa5dacb9aaaed438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Tue, 9 Dec 2025 14:49:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.vue | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pages/index/index.vue b/pages/index/index.vue index 5fb8e4b2..36b15d2c 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -402,12 +402,12 @@ export default { } // 如果没有热词,不启动滚动 - if (this.hotWord.length === 0) { + if (!this.hotWord || this.hotWord.length === 0) { return; } let index = 0; - const totalHeight = this.hotWord.length * this.itemHeight; + const totalHeight = this.hotWord && this.hotWord.length * this.itemHeight; const containerHeight = this.itemHeight; // 容器高度,只显示一项 this.scrollInterval = setInterval(() => { @@ -685,8 +685,8 @@ export default { page_size: 10 }, { silent: false }); - if (res.rows.length) { - let filterRes = this.filterShowList(res?.rows, 1); + if (res.rows && res.rows.length) { + let filterRes = this.filterShowList(res.rows, 1); filterRes.forEach(item => { item.pic_src = picUrl + item.pic_src }) @@ -705,11 +705,11 @@ export default { page_num: 1, page_size: 10 }, { silent: false }); - if (!res.rows.length) { + if (!res.rows || !res.rows.length) { this.serverLeftList = [] } - if (res.rows.length) { + if (res.rows && res.rows.length) { this.serverLeftList = res.rows let filterRes = this.filterShowList(res?.rows, 1); filterRes.forEach(item => { @@ -733,10 +733,10 @@ export default { page_num: 1, page_size: 10 }, { silent: false }); - if (!res.rows.length) { + if (!res.rows || !res.rows.length) { this.serverRightList = [] } - if (res.rows.length) { + if (res.rows && res.rows.length) { let filterRes = this.filterShowList(res?.rows, 1); filterRes.forEach(item => { item.pic_src = picUrl + item.pic_src @@ -756,7 +756,7 @@ export default { page_num: 1, page_size: 10 }, { silent: false }); - if (res.rows.length) { + if (res.rows && res.rows.length) { let filterRes = this.filterShowList(res?.rows, 1); filterRes.forEach(item => { item.pic_src = picUrl + item.pic_src @@ -778,7 +778,7 @@ export default { page_num: 1, page_size: 10 }, { silent: false }); - if (res.rows.length) { + if (res.rows && res.rows.length) { // let firstItem = res.rows[0]; // firstItem.pic_src = picUrl + firstItem.pic_src; // rightList.push(firstItem); @@ -941,10 +941,10 @@ export default { page_num: this.bottomPageNum, page_size: this.bottomPageSize }, { silent: val ? false : true }); - if (res.rows.length === 0) { + if (!res.rows || res.rows.length === 0) { return []; }; - if (res.rows.length == this.bottomPageSize) { + if (res.rows && res.rows.length == this.bottomPageSize) { this.flag = true } else { this.flag = false @@ -992,7 +992,7 @@ export default { isShop: 1, } const res = await request(apiArr2.getCateList, "POST", params, { slice: false }); - if (res.rows.length) { + if (res.rows && res.rows.length) { this.currentCategoryId = res.rows[0].id this.activeCategoryId = `category-${this.currentCategoryId}` this.getMechantList() @@ -1013,8 +1013,8 @@ export default { let latitude = uni.getStorageSync("location").lat; let longitude = uni.getStorageSync("location").lng; res.rows.forEach((item) => { - item.bigImg = item.album_images.split(","); - item.showImg = picUrl + item.album_images.split(",")[0]; + item.bigImg = item.album_images?.split(","); + item.showImg = picUrl + item.album_images?.split(",")[0]; const distanceInKm = calculateDistance( latitude, longitude, @@ -1042,7 +1042,7 @@ export default { return valueA - valueB; }); - if (res.rows.length == this.page_size) { + if (res.rows && res.rows.length == this.page_size) { this.page_num = this.page_num + 1; this.flag = true; } else { @@ -1069,8 +1069,9 @@ export default { * @returns {Array} 返回符合条件的数组内容 */ filterShowList(list, type) { - if (list && list.length == 0) return []; - return list.filter((item) => item.show_status == type); + if (list && list.length) { + return list.filter((item) => item.show_status == type); + } return []; }, async showSearch() { @@ -1081,7 +1082,7 @@ export default { async getSearchVal() { const res = await request(apiArr.hotWord, "POST", {}, { slice: false }); // 支持英文逗号和中文逗号分割 - this.hotWord = res.search_hot_word.split(/[,,]/) + this.hotWord = res.search_hot_word ? res.search_hot_word.split(/[,,]/) : [] }, async switchCategory(id) { @@ -1170,7 +1171,7 @@ export default { watch: { hotWord: { handler(newVal) { - if (newVal.length > 0) { + if (newVal && newVal.length > 0) { this.startScrollAnimation(); } },