From 26e596dd2119db74b42fa6ab69d0c439e4d55884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TOP=E7=B3=AF=E7=B1=B3?= <1130395124@qq.com> Date: Wed, 8 Mar 2023 14:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=89=E4=B8=ADbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/cate/cate.vue | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/components/cate/cate.vue b/src/components/cate/cate.vue index fa82962..78a3909 100644 --- a/src/components/cate/cate.vue +++ b/src/components/cate/cate.vue @@ -62,8 +62,10 @@ export default { itemId: "", // 栏目右边scroll-view用于滚动的id arr: [], // 储存距离顶部高度的数组 scrollRightTop: 0, // 右边栏目scroll-view的滚动条高度 - timer: null, // 定时器 wrapHeight: 0, + // 按ID选择 + timer: null, + activeIndex: 0, }; }, props: { @@ -237,14 +239,19 @@ export default { } } }, - switchCate(id) { - let idx = 0; + /** + * 按ID选中 + */ + async switchCate(id) { + if (this.arr.length == 0) { + await this.getMenuItemTop(); + } this.data.forEach((item, index) => { if (item.id == id) { - idx = index; + this.activeIndex = index; } }); - this.swichMenu(idx); + this.swichMenu(this.activeIndex); }, clickItem(id) { this.$emit("clickItem", id); @@ -254,6 +261,15 @@ export default { activeId(activeId) { this.switchCate(activeId); }, + arr(arr) { + clearTimeout(this.timer); + if (this.activeIndex > 0) { + const that = this; + this.timer = setTimeout(() => { + that.scrollRightTop = arr[that.activeIndex]; + }, 200); + } + }, }, };