博客列表 >微信小程序中的商品列表渲染

微信小程序中的商品列表渲染

美丽城堡
美丽城堡原创
2018年09月20日 23:12:004563浏览

goods.wxml

实例

moduls="模型名字,对应本文件中要引用的地方"   

src="模型所在的文件地址"

<wxs module="filters" src="./goods.wxs" />

<!-- 商品列表渲染 -->
<view class="goods-show">
    <block wx:for="{{goods}}" wx:key="id">
        <view class="goods-box">
            <image src='/image/home.png'></image>
            <view class="goods-name">{{item.goodsName}}</view>
            <view class="goods-price">¥ {{filters.toFix(item.goodsPrice,1)}}</view>
        </view>
    </block>
</view>

运行实例 »

点击 "运行实例" 按钮查看在线实例

goods.wxs

实例

var filters = {
	toFix: function(val,count){
		return parseFloat(val).toFixed(count);
	}
}

module.exports = {
	toFix: filters.toFix
}

运行实例 »

点击 "运行实例" 按钮查看在线实例

goods.wxss

实例

.goods-show{display: flex; flex-wrap: wrap;   }
.goods-box{width: 246rpx;  padding: 0 28prx; margin: 28rpx 0;  text-align: center; }

.goods-box image{width: 200rpx; height:200rpx; }
.goods-price{color: orange; font-size: 32rpx; }

运行实例 »

点击 "运行实例" 按钮查看在线实例

goods.js

实例

Page({
    data: {
        goods: [{
                goodsName: "商品1",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品2",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品3",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品4",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品5",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品6",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品7",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品8",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品9",
                goodsPrice: "66.6"
            },
            {
                goodsName: "商品9",
                goodsPrice: "66.6"
            },

        ]
    }

})

运行实例 »

点击 "运行实例" 按钮查看在线实例

app.wxss

实例

page{
	font-size: 28rpx; 
	color: #1a1a1a;
	font-family: microsoft yahei;
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议