name属性,作为模板的名字,然后在<template/>内定义代码片段。<!--
index: int
msg: string
time: string
-->
<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'
}
}
})is属性可以使用Mustache语法,来动态决定具体需要渲染哪个模板。<template name="odd">
<view> odd </view>
</template>
<template name="even">
<view> even </view>
</template>
<block a:for="{{[1, 2, 3, 4, 5]}}">
<template is="{{item % 2 == 0 ? 'even' : 'odd'}}"/>
</block>data传入的数据,但可以通过 onXX 绑定页面的逻辑处理函数。data传入的数据,因此应用会对此进行优化。如果该 template 的 data 没有改变,该片段 UI 并不会重新渲染。<import src="./a.axml"/> <!-- 相对路径 -->
<import src="/a.axml"/> <!-- 项目绝对路径 -->
<import src="third-party/x.axml"/> <!-- 第三方 npm 包路径 -->