Vue-Router内嵌Flexbox滚动异常问题求助
Flexbox滚动异常问题:滚动失效或内容底部截断
我有一个内部包含router-view的组件,用于展示Flexbox布局。尝试多种方案修复Flexbox滚动异常,要么完全无法滚动,要么滚动时无法到达底部——v-for渲染的最后一个元素会被截断。
Router-View组件代码
<template> <div class="modal" ref="modal"> <div class="modalcontent" ref="content"> <p class="goback" @click="closeAnimation" ref="goback">←</p> <div class="title"> <h1>Questions & Answers</h1> </div> <div class="routerview"> <router-view :posts="posts" v-slot="{ Component }"> <transition name="slide-in" mode="out-in"> <component :is="Component" /> </transition> </router-view> </div> </div> </div> </template> <style> .routerview { position: relative; width: 80%; margin: auto; overflow-y: scroll; left: 0; right: 0; outline: 10px red; } </style>
Flexbox布局组件代码
<template> <div class="container"> <div class="flex-container" ref="flexcontainer"> <div class="question" v-for="post in posts" :key="post._id" @click="this.$router.push(`/forum/question/${post._id}`)"> <h1 class="qTitle">{{ post.title }}</h1> <p class="qReplyAmt">{{ post.replies.length }} repl<span v-if="!plural(post.replies.length)">y</span><span v-else>ies</span></p> </div> </div> <p>You've reached the end</p> </div> </template> <style scoped> .question { width: 98%; height: fit-content; min-height: 0; background-color: whitesmoke; border-radius: 10px; padding: 10px 10px 2px 15px; cursor: pointer; transition: all 200ms ease-out; } .question:hover { background-color: rgb(255, 107, 107); color: white; } .qTitle { display: block; } .qReplyAmt { position: relative; top: -5px; } .flex-container { display: flex; align-items: center; flex-direction: column-reverse; width: 100%; gap: 15px; flex: 1; } </style>
已尝试的方案
- 为
.container、.routerview、.flex-container设置高度 - 为
.container、.routerview、.flex-container设置overflow-y为auto或scroll - 其他多种修复Flexbox滚动问题的方案
内容的提问来源于stack exchange,提问作者gaming man
相关产品推荐
相关产品推荐

