一、components文件夹中,加入对应的组件包
二、页面配置
1、json:“usingComponents”: {}
"recycle-view": "/components/miniprogram-recycle-view/recycle-view",
"recycle-item": "/components/miniprogram-recycle-view/recycle-item"
2、js:
const createRecycleContext = require('../../../components/miniprogram-recycle-view/index.js')
const imgUrlList = [
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSEV5QjxLDJaL6ibHLSZ02TIcve0ocPXrdTVqGGbqAmh5Mw9V7504dlEiatSvnyibibHCrVQO2GEYsJicPA/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_png/GEWVeJPFkSHALb0g5rCc4Jf5IqDfdwhWJ43I1IvriaV5uFr9fLAuv3uxHR7DQstbIxhNXFoQEcxGzWwzQUDBd6Q/0?wx_fmt=png',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSGqys4ibO2a8L9nnIgH0ibjNXfbicNbZQQYfxxUpmicQglAEYQ2btVXjOhY9gRtSTCxKvAlKFek7sRUFA/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSH2Eic4Lt0HkZeEN08pWXTticVRgyNGgBVHMJwMtRhmB0hE4m4alSuwsBk3uBBOhdCr91bZlSFbYhFg/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/mmbiz_jpg/TcDuyasB5T3Eg34AYwjMw7xbEK2n01ekiaicPiaMInEMTkOQtuv1yke5KziaYF4MLia4IAbxlm0m5NxkibicFg4IZ92EA/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSFrhQolODuh9lGqFKoicqKGxweRdS2zzibxicBMYkTic4WCJrbBNqoMchCWf02UbOvMBI6d32TAKFuqTQ/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/mmbiz_jpg/TcDuyasB5T0MfAGwtAs4jz0vTC0PHJEv2UErsjBhNDNujSwLhy7icf0DjDe7BYSIFkwqpMbekcwKDBic0ygBoFtw/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSGrMuuicv6QLQAe74FH1KrGUOq8VMe3Ya63tiaqaMNQibvB4T3SLoEWV3WrMvlySd3NXRXJGG75LAtjA/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSEQF22uXNecrTYIrCsEwo9Zolu6XnibTXNaZ1c19RozKjLqmR4oWl3DZhpLcDzwmtMOmIOuNuricrNA/0?wx_fmt=jpeg',
'http://mmbiz.qpic.cn/sz_mmbiz_jpg/GEWVeJPFkSEQF22uXNecrTYIrCsEwo9ZhibT6gPEoZfiaRGy9w9QyWB2vtOkxYUJPcEjePQTrVYpRF0PqicC4EEvw/0?wx_fmt=jpeg'
]
const rpx2px = (rpx) => (rpx / 750) * wx.getSystemInfoSync().windowWidth
const px2rpx = (px) => (px / wx.getSystemInfoSync().windowWidth) * 750
Page({
data: {
rheight:0,
rwidth:0,
urls5: [
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-1.jpg?sign=ff17b6597c5659186d54469e6122d153&t=1590025404',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-2.jpg?sign=7ccd10f793df154311f15a7b15d9ba57&t=1590025418',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-3.jpg?sign=d71bb290f896e14bb800d0fb807f6764&t=1590025427',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-4.jpg?sign=37d3fc32fe841a137e56b54cec2807c8&t=1590025434',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-5.jpg?sign=785abbd12c4fa70454ef4bd7c3961536&t=1590025441',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-2.jpg?sign=7ccd10f793df154311f15a7b15d9ba57&t=1590025418',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-3.jpg?sign=d71bb290f896e14bb800d0fb807f6764&t=1590025427',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-4.jpg?sign=37d3fc32fe841a137e56b54cec2807c8&t=1590025434',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-5.jpg?sign=785abbd12c4fa70454ef4bd7c3961536&t=1590025441',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-2.jpg?sign=7ccd10f793df154311f15a7b15d9ba57&t=1590025418',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-3.jpg?sign=d71bb290f896e14bb800d0fb807f6764&t=1590025427',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-4.jpg?sign=37d3fc32fe841a137e56b54cec2807c8&t=1590025434',
'https://656e-env-9eb476-1258886794.tcb.qcloud.la/images/album/photo-5.jpg?sign=785abbd12c4fa70454ef4bd7c3961536&t=1590025441'
],
},
,
onLoad() {
const ctx = createRecycleContext({
id: 'recycleId',
dataKey: 'recycleList',
page: this,
itemSize:
this.itemSizeFunc
})
ctx.append(urls5)
},
itemSizeFunc: function (item, index) {
return {
height: rpx2px(600),
width: rpx2px(750)
}
},
this.setData({
rheight:px2rpx(wx.getSystemInfoSync().windowWidth)*wx.getSystemInfoSync().windowHeight/wx.getSystemInfoSync().windowWidth,
rwidth: px2rpx(wx.getSystemInfoSync().windowWidth),
logs: (wx.getStorageSync('logs') || []).map(log => {
return {
date: util.formatTime(new Date(log)),
timeStamp: log
}
})
})
console.log("h====="+this.data.rheight+","+this.data.rwidth)
})
3、wxml:
<recycle-view batch="{{batchSetRecycleData}}" id="recycleId" hidden="{{hide0}}">
<recycle-item wx:for="{{recycleList}}" wx:key="id" class="item">
每个子项的view写在这。。。
</recycle-item>
</recycle-view>
|