How can I make slider in the card deck group on the bootstrap vue?(如何在 bootstrap vue 的卡片组组中制作滑块?)
问题描述
我使用本教程制作卡片组:
我该怎么做?
要达到这个结果,你必须使用一些 methods
, computed
属性和样式,这里是 工作示例 和 演示:
<模板><div class="动画淡入"><b卡组套牌>
I make card deck group using this tutorial : https://bootstrap-vue.js.org/docs/components/card/#card-deck-groups
My script like this :
<template>
<div class="animated fadeIn">
<b-card-group deck v-for="row in formattedClubs">
<b-card v-for="club in row"
img-src="https://placekitten.com/g/300/450"
img-alt="Img"
img-top>
<h4 class="card-title">
{{club.description}}
</h4>
<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>
</div>
</template>
<script>
export default {
data: function () {
return {
clubs: [
{id:1, description:'chelsea is the best club in the world and chelsea has a great player', price:1000, country:'england'},
{id:2, description:'liverpool has salah', price:900, country:'england'},
{id:3, description:'mu fans', price:800, country:'england'},
{id:4, description:'city has a great coach. Thas is guardiola', price:700, country:'england'},
{id:5, description:'arsenal player', price:600, country:'england'},
{id:6, description:'tottenham in london', price:500, country:'england'},
{id:7, description:'juventus stadium', price:400, country:'italy'},
{id:8, description:'madrid sell ronaldo', price:300, country:'spain'},
{id:9, description:'barcelona in the spain', price:200, country:'spain'},
{id:10, description:'psg buys neymar at a fantastic price', 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>
I want to add slider. So I want the slider like this :
How can I do it?
To achieve that result you have to use some methods
, computed
properties and styles, here a working example and demo:
<template>
<div class="animated fadeIn ">
<b-card-group deck >
<b-card v-for="(club,index) in currentPageClubs" :key="index"
img-src="https://placekitten.com/g/300/300"
img-alt="Img"
img-top >
<h4 class="card-title">
{{club.description}}
</h4>
<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>
<div class="card-pagination">
<div class="page-index" v-for="i in nbPages" :key="i" @click="goto(i)" :class={active:currentPage(i)}></div>
</div>
</div>
</template>
<script>
export default {
data: function () {
return {
clubs: [
{id:1, description:'chelsea is the best club in the world and chelsea has a great player', price:1000, country:'england'},
{id:2, description:'liverpool has salah', price:900, country:'england'},
{id:3, description:'mu fans', price:800, country:'england'},
{id:4, description:'city has a great coach. Thas is guardiola', price:700, country:'england'},
{id:5, description:'arsenal player', price:600, country:'england'},
{id:6, description:'tottenham in london', price:500, country:'england'},
{id:7, description:'juventus stadium', price:400, country:'italy'},
{id:8, description:'madrid sell ronaldo', price:300, country:'spain'},
{id:9, description:'barcelona in the spain', price:200, country:'spain'},
{id:10, description:'psg buys neymar at a fantastic price', price:100, country:'france'}
],
paginatedClubs:[],
nbPages:0,
nbRowPerPage:4,
currentPageIndex:0
}
},
computed: {
formattedClubs() {
return this.clubs.reduce((c, n, i) => {
if (i % 4 === 0) c.push([]);
c[c.length - 1].push(n);
return c;
}, []);
},
currentPageClubs(){
this.createPages();
return this.paginatedClubs[this.currentPageIndex];
}
},
methods:{
currentPage(i){
return i-1===this.currentPageIndex;
},
createPages() {
let lengthAll = Object.keys(this.clubs).length;
this.nbPages = 0;
for (let i = 0; i < lengthAll; i = i + this.nbRowPerPage) {
this.paginatedClubs[this.nbPages] = this.clubs.slice(
i,
i + this.nbRowPerPage
);
this.nbPages++;
}
},
goto(i){
this.currentPageIndex=i-1;
}
}
}
</script>
<style>
.card-pagination{
display:flex;
align-items: center;
justify-content: center;
padding:20px;
}
.page-index{
margin-left:10px;
width:15px;
height:15px;
border-radius:15px;
background:#007bff
}
.active{
width:20px;
height:20px;
border-radius:20px;
}
</style>
这篇关于如何在 bootstrap vue 的卡片组组中制作滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 bootstrap vue 的卡片组组中制作滑块?
基础教程推荐
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 动态更新多个选择框 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 我什么时候应该在导入时使用方括号 2022-01-01