微信小程序的一个典型列表页面

wxml

<import src="../templete/templete" />
<view class="content">
<view class="img">
<image src="../images/haibao/haibao-1.jpg" style="width:100%;height:230px;"></image>
</view>

<view class="nav">
<view class="nav-item">
<view><image src="../images/icon_type.png" style="height:25px;width:23px"></image></view>
<view>菜谱分类</view>
</view>
<view class="nav-item">
<view><image src="../images/icon_type.png" style="height:25px;width:23px"></image></view>
<view>菜谱分类</view>
</view>
<view class="nav-item">
<view><image src="../images/icon_type.png" style="height:25px;width:23px"></image></view>
<view>菜谱分类</view>
</view>
<view class="nav-item">
<view><image src="../images/icon_type.png" style="height:25px;width:23px"></image></view>
<view>菜谱分类</view>
</view>
</view>
<view class="hr"></view>
<view class="head">
<view>香哈头条</view>
<view class="right">></view>
</view>
<view class="list">
<template is="cooks" data="{{array}}" />
</view>
</view>

其中使用了模板
在项目中引入模板

模板的内容定义

<template name="cooks">
<block wx:for="{{array}}">
  <view class="item" bindtap="seeDetail" id="0">
    <image src="{{item.img}}" style="width:75px;height:58px;"></image>

  <view class="desc">
    <view class="title">{{item.title}} </view>
    <view class="count">
      <view>{{item.type}}</view>
      <view class="liulan">{{item.liulan}}</view>
      <view class="pinglun"> {{item.pinglun}}</view>
    </view>
  </view>
</view>
  <view class="hr2"></view>
</block>
</template>

wxss

/**index.wxss**/
.nav{
  display: flex;
  flex-direction: row;
  text-align:center
}
.nav-item{
  width: 25%;
  margin-top:20px;
  font-size: 12px;
}
.hr{
  height: 5px;
  background-color: #cccccc;
  margin-top: 10px;
  opacity: 0.2
}
.head{
  display: flex;
  flex-direction: row;
  margin: 10px;
  font-size: 13px;
  color: #999999
}
.right{
  position: absolute;
  right: 10px;
  color: #cccccc
}
.hr2{
  height: 2px;
  background-color: #cccccc;
  opacity: 0.2;

}
.item{
  display: flex;
  flex-direction: row;
  margin-left: 10px;
  margin-bottom: 5px;
}
.desc{
  margin-left: 20px;
  line-height: 30px;
}
.title{
  font-weight: bold;
}
.count{
  display: flex;
  flex-direction: row;
  font-size: 12px;
  color: #999999
}
.liulan{
  position: absolute;
  right: 50px;
}
.pinglun{
  position: absolute;
  right: 10px;
}

js

//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    array:[]
  },
  onLoad:function(){
    var array = this.iniData();
    this.setData({array:array});
  },
  iniData:function(){
    var array=[];
    var object1 = new Object();
    object1.img="../images/haibao/haibao-1.jpg";
    object1.title="爱心早餐";
    object1.type="健康养生";
    object1.liulan="20926浏览";
    object1.pinglun = "7评论"

    array[0] =object1;
    array[1] =object1;
    array[2] = object1;
    array[3] = object1;
    return array;
  }
 
})

预览界面

在这里插入图片描述

参考资料:微信小程序开发图解案例教程

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值