mos*_*toh 5 twitter-bootstrap vue.js bootstrap-4 vue-component vuejs2
我的 vue 组件是这样的:
<template>
...
<b-card-group deck deck v-for="row in formattedClubs">
<b-card v-for="club in row"
:title="club.description"
img-src="http://placehold.it/130?text=No-image"
img-alt="Img"
img-top>
<p class="card-text">
{{club.price}}
</p>
<p class="card-text">
{{club.country}}
</p>
<div slot="footer">
<b-btn variant="primary" block>Add</b-btn>
</div>
</b-card>
</b-card-group>
...
</template>
<script>
export default {
data: function () {
return {
clubs: [
{id:1, description:'chelsea', price:1000, country:'england'},
{id:2, description:'liverpool', price:900, country:'england'},
{id:3, description:'mu', price:800, country:'england'},
{id:4, description:'cit', price:700, country:'england'},
{id:5, description:'arsenal', price:600, country:'england'},
{id:6, description:'tottenham', price:500, country:'england'},
{id:7, description:'juventus', price:400, country:'italy'},
{id:8, description:'madrid', price:300, country:'spain'},
{id:9, description:'barcelona', price:200, country:'spain'},
{id:10, description:'psg', price:100, country:'france'}
]
}
},
computed: {
formattedClubs() {
return this.clubs.reduce((c, n, i) => {
if (i % 4 === 0) c.push([]);
c[c.length - 1].push(n);
return c;
}, []);
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
如果执行脚本,结果是这样的
第 1 行:
第 2 行:
第 3 行:
在第 1 行和第 2 行中,结果如我所料。1 行中有 4 列
但第三行不符合我的预期。1 行只有 2 列。应该有 4 列,其中 2 列已填充,2 列为空
我怎么解决这个问题?
使用 CSS 设置卡片的最大宽度...
.card-group .card {
max-width: 25%;
}
Run Code Online (Sandbox Code Playgroud)
演示: https: //www.codeply.com/go/DugupIrFxm
如果您使用卡片组,则需要计算排水沟......
.card-deck .card {
max-width: calc(25% - 30px);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13689 次 |
| 最近记录: |