在一个页面上定义一个片段,然后在不同的地方使用,相比组件更方便一点。
template 使用 name定义别名 ,使用 is 调用模板 别名。
<template name="msgItem"><view><text> {{index}}: {{msg}} </text><text> Time: {{time}} </text></view> </template> // 使用模板 // 使用 is 属性,声明需要的使用的模板,然后将模板所需要的 data 传入,如:<template is="msgItem" data="{{...item}}"/>
Page({data: {item: {index: 0,msg: 'this is a template',time: '2016-09-15'}} })