微信template模板

可参考微信开发者文档wxml模板
目录:
在这里插入图片描述
listItem.wxml中定义模板

<template name="listItem">      //name属性为模板的名字
  <view class="commonItem">
    <image src="{{img}}"></image>
    <view class="itemRight">
      <view class="itemTitle">{{title}}</view>
      <view class="itemFooter">
        <text>{{name}}</text>
        <text>{{date}}</text>
      </view>
    </view>
  </view>
</template>

listItem.wxss

.commonItem{
  width: 646rpx;
  height: 160rpx;
  background:rgba(244,244,244,1);
  box-shadow:0rpx 1rpx 7rpx 0rpx rgba(139,139,139,0.36);
  border-radius:0rpx 30rpx 30rpx 0rpx;
  margin:0 auto;
  display: flex;
  align-items: center;
  padding: 25rpx 30rpx;
  box-sizing: border-box;
  margin-top: 35rpx;
}
.commonItem image{
  width: 130rpx;
  height: 108rpx;
  margin-right: 30rpx;
}
.itemRight{
 /* flex: 100%; */            ----------在弹性盒子中慎用flex:100%;或者width:100%;
 width: 415rpx;
 height: 100%;
 display: flex;
 flex-direction: column;
 justify-content: space-around;
}
.itemTitle{
  font-size:30rpx;
  word-break: keep-all;
  word-wrap: break-word;
  white-space:pre-line;
}
.itemFooter{
  font-size:24rpx;
}

在相对应的组件中(.wxml)使用模板:

<import src="../../../../template/listItem/listItem.wxml" />      -------------------用import方式(写相对路径)引入模板(include引入方式不适合这里)
<template is="listItem" data="{{...data}}"/>                         -------------------使用...可在模板中少写item,is 属性可以使用 Mustache 语法,来动态决定具体需要渲染哪个模板

在相对应的组件中(.wxss)使用模板:

@import "../../../../template/listItem/listItem.wxss";
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值