【微信小程序】框架wxml(四)wxml模板

本文详细探讨了微信小程序中wxml模板的使用,包括如何在wxml中定义template的样式,并介绍了template对Mustache语句的支持,帮助开发者更好地理解和运用这一功能。

1.首先在wxml中定义template的样式

<template name="msgItem">
  <view>
    <text> {{index}}: {{msg}} </text>
    <text> Time: {{time}} </text>
  </view>
</template>
2.在js中写入几组数据

// pages/wxml2/wxml2.js
Page({
  data: {
    item1: {
      index: 0,
      msg: 'this is the first template',
      time: '2016-09-15'
    },item2: {
      index: 1,
      msg: 'this is the second template',
      time: '2016-09-30'
    }, item3: {
      index: 2,
      msg: 'this is the third template',
      time: '2016-10-09'
    }
  }
})
3.在wxml中使用template模板

<template is="msgItem" data="{{...item1}}"/>
<template is="msgItem" data="{{...item2}}"/>
<template is="msgItem" data="{{...item3}}"/>
4.效果图


此外,template支持Mustache语句

<block wx:for="{{[1, 2, 3, 4, 5]}}">
    <text>{{item}}</text>
    <template is="{{item % 2 == 0 ? 'even' : 'odd'}}"/>
</block>
效果图↓



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值