【template、import、include】微信小程序:模板(template)、引用(import、include)说明

模板(template):

定义模板

<template name="[String]">
  <!-- 模板代码 -->
   <view>
     <text> {{index}}: {{msg}} </text>
     <text> Time: {{time}} </text>
    </view>
</template>

属性 name 必须,命名该模板。

 

使用模板

1 <template is="msgItem" data="{{...item}}"/>
1 Page({
2   data: {
3     item: {
4       index: 0,
5       msg: 'this is a template',
6       time: '2016-09-15'
7     }
8   }
9 })

属性:

is 【必须】 指明要使用的模板名称,可以是Mustache语法生成的名称。

data 【可选】用于设置模板所需要的数据,模板定义中可以直接使用该数据

 

import

import可以在该文件中使用目标文件定义的template,语法:

1 <import src="[文件路径]"/>

import只能获取目标文件中的template部份,并且不会获取目标文件中import中的模板。

 

include

include 可以将目标文件除了 <template/> <wxs/> 外的整个代码引入,相当于是拷贝到 include 位置,语法:

1 <include src="[文件路径]"/>

 

posted @ 2018-10-25 10:58  1024记忆  阅读(279)  评论(0编辑  收藏  举报