list.vue
3.05 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
128
129
130
131
132
133
134
135
136
137
<template>
<div class="goods-box">
<ul class="cardlist card-large">
<li class="card" v-for="item in products">
<div class="card-pic">
<a href="">
<img :src="item.goodsList[0].imagesUrl | resize 372 499" alt="{{item.productName}}">
</a>
</div>
<div class="card-bd">
<h2 class="card-label">
<a href="">{{item.productName}}</a>
</h2>
<span class="good-price" :class="{'old-price': item.marketPrice}" v-if="item.marketPrice">¥ {{item.marketPrice}}</span>
<span class="good-price" :class="{'sale-price': item.marketPrice}">¥ {{item.salesPrice}}</span>
</div>
</li>
</ul>
</div>
</template>
<script>
let $ = require('yoho-jquery');
module.exports = {
props: {
/* 请求地址 */
url: {
type: String,
required: true
},
initData: Array, /* 初始数据, 应该只单次绑定, 然后fetch数据全靠url */
query: Object /* 请求参数 */
},
data: function() {
return {
products: []
};
},
methods: {
fetch: function() {
let self = this;
$.ajax({
url: this.url,
type: 'POST',
})
.then(result => {
self.$set('products', self.products.concat(result.data.productList));
});
}
},
created: function() {
// 有初始数据,用初始数据
if (this.initData) {
self.$set('products', self.products.concat(this.initData));
} else if (this.url) {
this.fetch();
}
},
};
</script>
<style>
@import "../../scss/common/color";
.cardlist {
list-style: none;
margin: 0;
padding: 0;
}
.card-large {
.card {
float: left;
width: 372px;
margin-right: 6px;
&:nth-child(2n) {
margin-right: 0;
}
}
.card-pic {
width: 100%;
height: 499px;
a,
img {
display: block;
width: 100%;
height: 100%;
}
}
.card-bd {
min-height: 180px;
margin-left: 30px;
margin-right: 30px;
padding-top: 25px;
text-align: center;
font-size: 24px;
}
.card-label {
margin: 0 0 10px;
font-size: inherit;
font-weight: normal;
}
}
.good-price {
color: #b0b0b0;
margin-right: 10px;
&:last-of-type {
margin-right: 0;
}
&.old-price {
text-decoration: line-through;
}
&.sale-price {
color: $red;
}
}
.drawer-slide {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.6);
}
.drawer-main {
position: absolute;
top: 0;
right: 0;
bottom: 0;
min-width: 80%;
max-width: 100%;
background-color: #fff;
}
</style>