我是靠谱客的博主 哭泣高跟鞋,这篇文章主要介绍小程序瀑布流组件,现在分享给大家,希望可以做个参考。

简单的uniapp瀑布流 拿走不谢 记得点赞

组件

复制代码
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<template> <view class="container"> <view class="waterfall_left"> <view @tap='goodInfo(item.id)' class="waterfall_item" v-for="(item,index) in listLeft" :key="index"> <view class="item_img"> <image :src="item.image" mode="widthFix" @load="considerPush"></image> </view> <view class="item_info"> <view class="item_info_title">{{item.goods_name}}</view> <view class="item_info_note">{{item.integral}}</view> </view> </view> </view> <view class="waterfall_right"> <view @tap='goodInfo(item.id)' class="waterfall_item" v-for="(item,index) in listRight" :key="index"> <view class="item_img"> <image :src="item.image" mode="widthFix" @load="considerPush"></image> </view> <view class="item_info"> <view class="item_info_title">{{item.goods_name}}</view> <view class="item_info_note">{{item.integral}}</view> </view> </view> </view> </view> </template> <script> export default { name: "zero-waterfall", props: { // 需要在使用页面 onPageScroll 传进来 list: { type: Array, required: true, default: [] }, // 图片裁剪模式 imgMode: { type: String, default: 'widthFix' }, }, data() { return { listLeft: [], listRight: [], newList: [], } }, watch: { list(newValue, oldValue) { this.newList = newValue.slice(oldValue.length); this.considerPush() }, }, mounted() { this.init() }, methods: { // 触发重新排列 init() { this.newList = [...this.list]; this.listLeft = []; this.listRight = []; if (this.newList.length != 0) { this.listLeft.push(this.newList.shift()); //触发排列 // this.listRight.push(this.newList[1]); //触发排列 } }, // 清空数据列表 clear() { this.listLeft = []; this.listRight = []; // 同时清除父组件列表中的数据 this.$emit('clear', []); this.newList = []; }, goodInfo(id){ this.$emit('goodInfo',id) }, // 计算排列 considerPush() { if (this.newList.length == 0) return; //没有数据了 let leftH = 0, rightH = 0; //左右高度 var query = uni.createSelectorQuery().in(this); query.selectAll('.waterfall_left').boundingClientRect() query.selectAll('.waterfall_right').boundingClientRect() query.exec(res => { // console.log('结果',res) leftH = res[0].length != 0 ? res[0][0].height : 0; //防止查询不到做个处理 rightH = res[1].length != 0 ? res[1][0].height : 0; if (leftH == rightH || leftH < rightH) { // 相等 || 左边小 this.listLeft.push(this.newList.shift()); } else { // 右边小 this.listRight.push(this.newList.shift()); } }); }, } } </script> <style lang="scss" scoped> .container { display: flex; flex-flow: row nowrap; justify-content: space-around; align-items: flex-start; } .waterfall_left, .waterfall_right { width: 46%; // border: 1px solid red; } .waterfall_item { width: 100%; margin: 10rpx 0 40rpx 0; background-color: #FFFFFF; border-radius: 15rpx; overflow: hidden; .item_img { width: 100%; image { width: 100%; overflow: hidden; } } .item_info { padding: 10rpx 0; .item_info_title { color: #333333; font-size: 32rpx; padding: 10rpx 0; } .item_info_note { color: #666666; font-size: 28rpx; } } } </style>

页面引用

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//页面引用 <zero-waterfall @goodInfo='goodInfo' :list="storeData"></zero-waterfall> //引用 import zeroWaterfall from '../../../components/zero-waterfall'; //注册 components: { zeroWaterfall }, //在methods里点击进入详情页面 goodInfo(id) { uni.navigateTo({ url: './goodInfo?id=' + id + '&score=' + this.score }) }

最后

以上就是哭泣高跟鞋最近收集整理的关于小程序瀑布流组件的全部内容,更多相关小程序瀑布流组件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部