javascript - 在 vue 中将卡片堆叠在一起
问题描述
我有一个小的 vue 片段(片段有我原来的 v-for 和 v-if 条件,但我无法让它读取数组,所以它现在只是硬编码)
无论如何,它会产生 3 张卡片,一张在另一张之上。我试图弄清楚 vue 中是否有任何内置的东西,我可以让它们像甲板一样堆叠在一起,你只能看到每张卡片顶部的大约 20%,然后单击一个展开它们,像手风琴一样。
我尝试在底部设置负边距,但没有生效。有没有更好的方法来解决这个问题?
export default{
data() {
return {
copiedUsers:[
{copied_user_email: "testuser@mail.com"},
{copied_user_email: "testuser2@mail.com"},
{copied_user_email: "testuser3@mail.com"}
]
}
}
}
.card {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 1px solid #dee2e6;
border-radius: 0.5rem
margin-bottom:-80px;
}
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.js"></script>
<div id='app'>
<div v-for="(copy, idx) in copiedUsers" :key="copy.id">
<div
class="card"
:style="{
top: idx * 10 + 'px', // <-- dynamic top
left: idx * 6 + 'px' // <-- dynamic left
}">
</div>
</div>
</div>
解决方案
您可以使用样式绑定按照自己的方式工作,:style
并根据索引添加特定范围。
这是一个了解这个想法的例子:
new Vue({
el: '#app',
data: {
copiedUsers:[
{copied_user_email: "testuser@mail.com"},
{copied_user_email: "testuser2@mail.com"},
{copied_user_email: "testuser3@mail.com"}
]
}
})
.card {
position: absolute;
width: 40px;
height: 65px;
background-color: #777;
border: 1px solid #333;
}
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.js"></script>
<div id='app'>
<div v-for="(copy, idx) in copiedUsers" :key="copy.id">
<div
class="card"
:style="{
top: idx * 10 + 'px', // <-- dynamic top
left: idx * 6 + 'px' // <-- dynamic left
}">
</div>
</div>
</div>
您还可以使用动态margins
或paddings
. 为了使其易于理解和模板干净,您可以创建一个计算属性。
推荐阅读
- flutter - 在 Flutter 应用程序中处理应用程序布局
- python - 基于约束的数据框列生成
- c# - .net core3 grpc 服务器端流永远
- apache-camel - 如何实现有关多播的路由?
- python - Pandas:根据多个条件生成句子并将它们显示在单独的列中
- python - 在 Jupyter Notebook 上清理并制作可读的条形图
- android - Xml 和 Java 编码未正确构建
- android - Firebase 应用程序未在缓慢的互联网连接中获取数据
- officer - R的官员和记者包之间的比较
- html - Veutify 动画 v-data-table