grass-artilces.vue
2.45 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
<template>
<div class="articles-wrapper" v-if="articleList">
<div class="articles-container">
<p class="title">推荐搭配({{articleTotal}})</p>
<ul>
<li v-for="item in articleList" @click="showAricleImages" :data-id="item.articleId" :data-index="item.imageindex">
<img v-lazy="item.coverImage">
</li>
</ul>
</div>
</div>
</template>
<script>
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('product');
export default {
name: 'grassArtilces',
props: {
listdata: {
type: Object,
default: {}
},
productId: {
type: Number
}
},
data() {
return {
imgs: [],
initialIndex: 0,
articleTotal: 0
};
},
computed: {
articleList() { // 获取到listdata之后处理数据
if (this.listdata && this.listdata.list) {
this.imgs = this.listdata.imageList || [];
this.articleTotal = this.listdata.list.length || 0;
}
return this.listdata.list;
}
},
activated() {
},
methods: {
...mapActions(['fetchGrassArticleImages']),
showAricleImages(e) { // 点击推荐小图展示文章内大图
this.initialIndex = parseInt(e.currentTarget.dataset.index, 10) || 0;
this.$createImagePreview({
imgs: this.imgs,
initialIndex: this.initialIndex,
loop: false,
speed: 500,
onChange: (i) => {
this.initialIndex = i;
}
}).show();
},
}
};
</script>
<style lang="scss" scoped>
.articles-wrapper {
position: relative;
width: 100%;
margin: 30px 0;
.articles-container {
position: relative;
padding: 0 40px;
overflow: hidden;
.title {
font-size: 32px;
line-height: 44px;
font-weight: 600;
}
ul {
position: relative;
width: 100%;
margin: 20px auto;
list-style: none;
padding: 0;
overflow: hidden;
li {
display: flex;
justify-content: center;
align-items: center;
float: left;
width: 222px;
height: 222px;
margin: 0 0 2px 0;
box-sizing: border-box;
border-radius: 8px;
overflow: hidden;
img {
height: 100%;
float: left;
margin: 0 auto;
}
}
li:nth-child(3n + 2) {
margin: 0 2px;
}
}
}
}
</style>