<div
style="width: 220px; height: calc(100vh - 1.6rem)"
class="scroll hide-scroll"
ref="menu"
>
<div
v-for="(item, i) in 100"
:key="i"
>
<div>{{ item}}</div>
</div>
</div>
.scroll {
overflow-y: auto;
}
.scroll::-webkit-scrollbar {
width: 8px;
}
.hide-scroll::-webkit-scrollbar {
width: 0px;
}
.scroll::-webkit-scrollbar-thumb {
background: #ccc;
border-radius: 5px;
}
.scroll::-webkit-scrollbar-thumb:hover {
background: #d7f8f5;
}
mounted() {
console.log(localStorage.getItem("menu"));
this.$nextTick(() => {
if (localStorage.getItem("menu")) {
this.$refs.menu.scrollTo({
top: localStorage.getItem("menu") * 1,
});
}
});
this.$refs.menu.addEventListener("scroll", this.handleScroll);
},
methods: {
handleScroll() {
var scrollTop = this.$refs.menu.scrollTop;
localStorage.setItem("menu", scrollTop);
},
},