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); + } + }, }, };