许多商城小程序中,,,,,,一般的商品列表是以流式结构方式展示,,,,,,下面为各人介绍小程序怎样制作商品列表流式结构??

流式结构也叫百分比结构 把元素的宽,高,margin,padding不再用牢靠数值,改用百分比, 这样元素的宽,高,margin,padding会凭证页面的尺寸随时 调解已抵达顺应目今页面的目的.
先看效果:

如上图所示,,,,,,为了能够看的更直观一点我给结构设置了红色虚线边框,,,,,,整体页面凭证元素的百分比举行结构。。。。。
直接看代码:
<scroll-view scroll-y="true" style="height:{{scrollH}}px" bindscrolltolower="loadImages">
<view class="goods" style="width:100%">
<view class="mg_item">
<view wx:for="{{col1}}" wx:key="id">
<view class="item_info">
<image src="{{item.imageurl}}" style="width:100%;height:{{item.height}}px"></image>
</view>
<view class="product-name">
{{item.name}}
</view>
<view class="product-price-wrap">
<p class="product-price-new">¥{{item.newprice}}</p>
<p class="product-price-old">¥{{item.oldprice}}</p>
<p class="discount">{{item.discount}}折</p>
</view>
</view>
</view>
<view class="mg_item">
<view wx:for="{{col2}}" wx:key="id">
<view class="item_info">
<image src="{{item.imageurl}}" style="width:100%;height:{{item.height}}px"></image>
</view>
<view class="product-name">
{{item.name}}
</view>
<view class="product-price-wrap">
<p class="product-price-new">¥{{item.newprice}}</p>
<p class="product-price-old">¥{{item.oldprice}}</p>
<p class="discount">{{item.discount}}折</p>
</view>
</view>
</view>
</view>
</scroll-view>
<view style="display:none">
<image wx:for="{{images}}" wx:key="id" id="{{item.id}}" src="{{item.imageurl}}" bindload="onImageLoad"></image>
</view>
通过审查class标签发明有两个img_item ,,,,,,以是接纳的是左右划分加载数据方式。。。。。
Page({
data: {
scrollH: 0,
imgWidth: 0,
loadingCount: 0,
images: [],
col1: [],
col2: []
},
onLoad: function () {
wx.getSystemInfo({
success: (res) => {
let ww = res.windowWidth;
let wh = res.windowHeight;
let imgWidth = ww * 0.48;
let scrollH = wh;
this.setData({
scrollH: scrollH,
imgWidth: imgWidth
});
//加载首组图片
this.loadImages();
}
})
},
onImageLoad: function (e) {
let imageId = e.currentTarget.id;
let oImgW = e.detail.width; //图片原始宽度
let oImgH = e.detail.height; //图片原始高度
let imgWidth = this.data.imgWidth; //图片设置的宽度
let scale = imgWidth / oImgW; //比例盘算
let imgHeight = oImgH * scale; //自顺应高度
let images = this.data.images;
let imageObj = null;
for (let i = 0; i < images.length; i++) {
let img = images[i];
if (img.id === imageId) {
imageObj = img;
break;
}
}
imageObj.height = imgHeight;
let loadingCount = this.data.loadingCount - 1;
let col1 = this.data.col1;
let col2 = this.data.col2;
//判断目今图片添加到左列照旧右列
if (col1.length <= col2.length) {
col1.push(imageObj);
} else {
col2.push(imageObj);
}
let data = {
loadingCount: loadingCount,
col1: col1,
col2: col2
};
//目今这组图片已加载完毕,,,,,,则清空图片暂时加载区域的内容
if (!loadingCount) {
data.images = [];
}
this.setData(data);
},
loadImages: function () {
let images = [
{
goodId: 0,
name: '泊尔崖蜜蜜光面膜(5片盒装)',
url: 'bill',
imageurl: 'http://www.kesion.com/UploadFiles/2021-7/82/b3132703574748462334GRB.jpg',
newprice: "86",
oldprice: "88",
discount: "8.8",
height: 0,
},
{
goodId: 1,
name: '透无瑕矿物养护两用粉饼#03',
url: 'bill',
imageurl: 'http://www.kesion.com/UploadFiles/2021-7/82/b4132703574752056107TSC.jpg!75.webp',
newprice: "147.00",
oldprice: "150.00",
discount: "8.8",
height: 0,
},
{
goodId: 2,
name: '川水水光面膜(5片盒装)',
url: 'bill',
imageurl: 'http://www.kesion.com/UploadFiles/2021-7/82/b5132703574756118633QSA.jpg',
newprice: "86.00",
oldprice: "88.00",
discount: "8.8",
height: 0,
},
{
goodId: 3,
name: '蜜三色渐变咬唇膏3.2g 03蜜橙动心恋',
url: 'bill',
imageurl: 'http://www.kesion.com/UploadFiles/2021-7/82/b61327035747714312316IW.jpg',
newprice: "97.00",
oldprice: "99.00",
discount: "8.8",
height: 0,
},
{
goodId: 4,
name: '时焕颜亮采套装',
url: 'bill',
imageurl: 'http://www.kesion.com/UploadFiles/2021-7/82/b71327035747737749969ZZ.jpg',
newprice: "398.00",
oldprice: "459.00",
discount: "8.8",
height: 0,
}
];
let baseId = "img-" + (+new Date());
for (let i = 0; i < images.length; i++) {
images[i].id = baseId + "-" + i;
}
this.setData({
loadingCount: images.length,
images: images
});
}
})
如下代码:
**if (col1.length <= col2.length) {
col1.push(imageObj);
} else {
col2.push(imageObj);
}**
检索商品荟萃凭证高度划分放入两个荟萃中。。。。。
page{
height: 100%;
background-color: #F3F4F6;
}
/* 单个图片容器的样式 */
.img_item {
width: 48.5%;
margin: 2px;
display: inline-block;
vertical-align: top;
background-color: #ffffff;
font-size: 24rpx;
}
.item_info{
border-top:1px dashed red;
}
.product-name{
color: #000;
/* height: 28px; */
text-align:left;
margin: 0px 5px;
margin-bottom: 5px;
}
.product-price-wrap .product-price-new{
color: #e80080;
margin-left:5px;
font-weight:900;
}
.product-price-wrap .product-price-old{
color: #888;
text-decoration: line-through;
padding-left: 2px;
}
.product-price-wrap .discount{
margin-left: 30px;
background-color: #000;
color: #fff;
}
小程序工具提供多类型商城/门店小程序制作,,,,,,可视化编辑 1秒天生5步上线。。。。。通过拖拽、拼接??榻峁剐〕绦蛏坛且趁,,,,,,所看即所得,,,,,,只需要美工就能做出细腻商城。。。。。更多小程序市肆请审查:小程序市肆
KESION pp电子软件
KESION pp电子软件是海内领先的在线教育软件及私域社交电商软件服务提供商,,,,,,恒久专注于为企业提供在线教育软件及社交电商SaaS平台解决方案。。。。。
公司焦点产品云开店SaaS社交电商服务平台、在线教育SaaS服务平台、教育企业数字化SaaS云平台、企微营销助手、私有化自力安排品牌网校和在线教育咨询等。。。。。KESION 一直通过手艺立异,,,,,,提供产品和服务,,,,,,助力企业向数字化转型,,,,,,通过科技驱动商业刷新,,,,,,让商业变得更智慧!
现在,,,,,,小程序图片或者外地文件转成base64是不可够实现的,,,,,,以下是详细剖析:...
微信小程序最新入口中,,,,,,你也许还不知道这个入口,,,,,,就是来自于微信群谈天中,,,,,,若是你的微信群曾分享过小程序,,,,,,就会有这个入口显示。。。。。...