HomeBanner.vue
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<section class="home-banner">
<van-swipe
class="banner-swiper"
:autoplay="autoplay"
lazy-render
@change="handleChange"
>
<van-swipe-item
class="swiper-item"
v-for="(item, idx) in banners"
:key="idx"
>
<img
v-if="item.picUrl"
class="banner-img"
:src="item.picUrl"
@click="handleItem(item)"
/>
<div v-else class="banner-img white">
<div class="banner-img skeleton"></div>
</div>
</van-swipe-item>
<template #indicator>
<div class="nafmii-indicator">
<span
class="indicator-item"
:class="{ 'indicator-active': active == idx }"
v-for="(item, idx) in banners"
:key="idx"
/>
</div>
</template>
</van-swipe>
</section>
</template>
<script>
export default {
name: 'HomeBanner',
props: {
data: {
type: Object,
default: () => { return {} }
}
},
data () {
return {
active: 0,
}
},
computed: {
autoplay () {
const { carouseTime } = this.data || {}
// 默认5秒
return carouseTime && (carouseTime * 1000) || 5000
},
banners () {
const { carouseVOList } = this.data || {}
return carouseVOList || [{}, {}]
}
},
methods: {
handleItem (banner) {
const { linkUrl, linkType } = banner
},
handleChange (index) {
this.active = index
}
}
}
</script>
<style lang="less" scoped>
.white {
background: #eee;
}
@PaddingSize: 15;
.home-banner {
margin-top: @PaddingSize;
.banner-swiper {
.banner-img {
height: 145px;
border-radius: 5px;
width: 100%;
}
@PointSize: 5px;
.nafmii-indicator {
position: absolute;
left: 0;
bottom: 10px;
right: 0;
display: flex;
align-items: center;
justify-content: center;
height: @PointSize;
.indicator-item {
background: rgba(255, 255, 255, 0.4);
width: @PointSize;
height: @PointSize;
border-radius: calc(@PointSize / 2);
margin: 0 4px;
&.indicator-active {
background: white;
width: 21.5px;
}
}
}
}
}
</style>