vue设置overflow-y: auto;keepAlive滚动条位置不正确
时间: 2023-05-20 11:07:01 浏览: 421
可以尝试在keepAlive组件中添加一个ref属性,并在mounted生命周期中获取该组件的scrollTop属性,然后在activated生命周期中将scrollTop属性设置回去,以保持滚动条位置正确。具体代码如下:
<template>
<keep-alive ref="keepAlive">
<router-view></router-view>
</keep-alive>
</template>
<script>
export default {
mounted() {
this.scrollTop = this.$refs.keepAlive.$el.scrollTop;
},
activated() {
this.$refs.keepAlive.$el.scrollTop = this.scrollTop;
}
}
</script>
阅读全文