110 行
2.0 KiB
Vue
110 行
2.0 KiB
Vue
<template>
|
||
<!-- 轮播 -->
|
||
<view class="banner-swiper-wrap u-m-b-10" :style="{ padding: `${Py}rpx ${Px}rpx` }">
|
||
<swiper
|
||
:key="swiperKey"
|
||
:style="bannerBoxStyle"
|
||
class="banner-swiper square-dot"
|
||
:indicator-dots="list.length > 1"
|
||
:circular="list.length > 1"
|
||
:autoplay="list.length > 1"
|
||
interval="5000"
|
||
duration="500"
|
||
>
|
||
<swiper-item
|
||
v-for="(item, index) in list"
|
||
:key="item.image || index"
|
||
class="banner-swiper-item"
|
||
:style="{ borderRadius: borderRadius + 'rpx' }"
|
||
@tap="onSwiper(index)"
|
||
>
|
||
<image
|
||
class="banner-swiper__img"
|
||
:style="imageStyle"
|
||
:src="item.image"
|
||
mode="aspectFill"
|
||
:lazy-load="false"
|
||
></image>
|
||
</swiper-item>
|
||
</swiper>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
/**
|
||
* shBanner-轮播卡片
|
||
* @property {Array} list 轮播图数据,
|
||
* @property {String Number} height 轮播图组件高度,单位rpx(默认250)
|
||
* @property {String} borderRadius 圆角值
|
||
* @event {Function} click 点击轮播图时触发
|
||
*/
|
||
export default {
|
||
components: {},
|
||
data() {
|
||
return {};
|
||
},
|
||
props: {
|
||
Px: {
|
||
type: [Number, String],
|
||
default: 0
|
||
},
|
||
Py: {
|
||
type: [Number, String],
|
||
default: 0
|
||
},
|
||
list: {
|
||
type: Array,
|
||
default() {
|
||
return [];
|
||
}
|
||
},
|
||
borderRadius: {
|
||
type: [Number, String],
|
||
default: 0
|
||
},
|
||
height: {
|
||
type: [Number, String],
|
||
default: 250
|
||
}
|
||
},
|
||
computed: {
|
||
bannerBoxStyle() {
|
||
return {
|
||
width: '100%',
|
||
height: `${this.height}rpx`
|
||
};
|
||
},
|
||
imageStyle() {
|
||
return {
|
||
width: '100%',
|
||
height: `${this.height}rpx`,
|
||
borderRadius: `${this.borderRadius}rpx`
|
||
};
|
||
},
|
||
swiperKey() {
|
||
return `${this.height}-${this.list.map(item => item.image || '').join('|')}`;
|
||
}
|
||
},
|
||
methods: {
|
||
onSwiper(e) {
|
||
this.$tools.routerTo(this.list[e].path);
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.banner-swiper {
|
||
width: 100%;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.banner-swiper-item {
|
||
height: 100%;
|
||
}
|
||
|
||
.banner-swiper__img {
|
||
display: block;
|
||
}
|
||
</style>
|