waterfall-item.vue
1.8 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
<template>
<view class="waterfall-item-container">
<view class="waterfall-item" @tap="onTap">
<image :src="params.url" mode="widthFix" @load="emitHeight" @error="emitHeight"></image>
<view class="content">
<view>{{params.title}}</view>
<view class="money">{{params.money}}元</view>
<view style="margin: 0 0 8rpx 0;">
<text class="label">{{params.label}}</text>
</view>
<view class="shop-name">{{params.shop}}</view>
</view>
</view>
</view>
</template>
<script>
export default {
name:"helangWaterfallItem",
options:{
virtualHost: true
},
props:{
params:{
type: Object,
default(){
return {}
}
},
tag:{
type:String | Number,
default:''
},
index:{
type:Number,
default:-1
}
},
data() {
return {
};
},
methods:{
// 发出组件高度信息,在此处可以区分正确和错误的加载,给予错误的提示图片
emitHeight(e){
const query = uni.createSelectorQuery().in(this);
query.select('.waterfall-item-container').boundingClientRect(data => {
let height = Math.floor(data.height);
this.$emit("height",height,this.$props.tag);
}).exec();
},
onTap(){
this.$emit("click",this.$props.index,this.$props.tag);
}
}
}
</script>
<style lang="scss" scoped>
.waterfall-item{
padding: 16rpx;
background-color: #fff;
border-radius: 4px;
font-size: 28rpx;
color: #666;
image{
display: block;
width: 100%;
// 默认设置一个图片的大约值
height: 350rpx;
}
.content{
margin-top: 16rpx;
.money{
color: #fa3534;
margin-top: 8rpx;
}
.label{
background-color: #fa3534;
color: #fff;
font-size: 20rpx;
padding: 4rpx 16rpx;
border-radius: 20rpx;
}
.shop-name{
font-size: 20rpx;
color: #999;
}
}
}
</style>