swiper3dCom.vue
4.22 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<template>
<div class="swiper-3d-com" v-if="items && items.length">
<!-- 背景图片 -->
<div class="bg-box" v-if="setOptions.bg">
<img :src="setOptions.bg + SIGN.BIG" class="bg-img" />
</div>
<!-- 3D轮播 -->
<div class="carousel-3d-box">
<carousel-3d :autoplay="setOptions.autoplay" :autoplayTimeout="setOptions.autoplayTimeout" :autoplayHoverPause="setOptions.autoplayHoverPause" :display="setOptions.display" :width="getWidth()" :height="getHeight()" :inverseScaling="1000" :onMainSlideClick="onMainSlideClick">
<slide :index="index" v-for="(item, index) in items" :key="index">
<div class="item">
<div class="img-box">
<img :src="item.simg" class="img" />
</div>
<div class="base-box">
<img src="static/img/hot-sales-base.png" class="base-img" />
</div>
<div class="title-box" :style="{'backgroundImage': 'url(static/img/hot-sales-title.png)'}">
<div class="index">月销量第{{setOptions.sortArr[index]}}名</div>
<div class="title">
<div class="title-sub">
{{item.title}}
</div>
</div>
</div>
</div>
</slide>
</carousel-3d>
</div>
</div>
</template>
<script>
// 引入组件
import { Carousel3d, Slide } from 'vue-carousel-3d';
export default {
data: function () {
return {
setOptions: {
bg: null, // 背景图片
sortArr: ['一', '二', '三'], // 排名排序汉字字符串
display: 3, // 展示数量
autoplay: true, // 自动切换
autoplayTimeout: 5000, // 自动切换时长
autoplayHoverPause: true, // 悬停自动暂停
inverseScaling: 1000 // 反向缩放大小,数字越大缩放比例越大(暂时不使用这个参数,要配合width/height参数共同使用)
}
}
},
props: ["items", "options"],
components: {
Carousel3d,
Slide
},
computed: {
/**
* 计算宽度
*/
getWidth() {
return () => {
return (document.documentElement.clientWidth || document.body.clientWidth) * (760 / 750);
}
},
/**
* 计算高度
*/
getHeight() {
return () => {
return (document.documentElement.clientWidth || document.body.clientWidth) * (290 / 750);
}
}
},
methods: {
/**
* 合并选项
* @param {Object} options [配置选项]
*/
mergeOptions(options) {
if (typeof options === 'object' && options !== null) {
// 合并默认参数
Object.assign(this.setOptions, options);
}
},
/**
* 活动项目点击事件
* @param {Object} item [数据对象]
*/
onMainSlideClick(item) {
this.$emit('onMainSlideClick', item);
}
},
watch: {
/**
* 监听options参数变化
*/
options(newVal, oldVal) {
// 合并选项
this.mergeOptions(newVal);
}
},
mounted() {
this.$nextTick(() => {
// 合并选项
this.mergeOptions(this.options);
});
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less" scoped>
@import './swiper3dCom';
</style>