修复选中bug

This commit is contained in:
TOP糯米 2023-03-08 14:28:59 +08:00
parent bc819831f0
commit 26e596dd21
1 changed files with 21 additions and 5 deletions

View File

@ -62,8 +62,10 @@ export default {
itemId: "", // scroll-viewid itemId: "", // scroll-viewid
arr: [], // arr: [], //
scrollRightTop: 0, // scroll-view scrollRightTop: 0, // scroll-view
timer: null, //
wrapHeight: 0, wrapHeight: 0,
// ID
timer: null,
activeIndex: 0,
}; };
}, },
props: { 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) => { this.data.forEach((item, index) => {
if (item.id == id) { if (item.id == id) {
idx = index; this.activeIndex = index;
} }
}); });
this.swichMenu(idx); this.swichMenu(this.activeIndex);
}, },
clickItem(id) { clickItem(id) {
this.$emit("clickItem", id); this.$emit("clickItem", id);
@ -254,6 +261,15 @@ export default {
activeId(activeId) { activeId(activeId) {
this.switchCate(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);
}
},
}, },
}; };
</script> </script>