一、template模板
在home下新建模板文件夹templates,继续在templates里面新建temp.wxml:
```html
<!-- 定义模板 用name属性起名字 -->
<template name="tmpl1">
<view>这是模板1</view>
</template>
<template name="tmpl2">
<view>这是模板2</view>
</template>
```
```html
<!-- 1 通过import标签进行引入 -->
<import src="./templates/temp.wxml"></import>
<!-- 2 通过is属性指定模板 -->
<template is="tmpl1"></template>
<template is="tmpl2"></template>
```
可以往模板里面传值:
home.wxml中
```html
<import src="./templates/temp.wxml"></import>
<!-- 通过data属性向模板内部传入数据 -->
<template is="tmpl1" data="{{msg:'呵呵'}}"></template>
<template is="tmpl2" data="{{aaa:'哈哈'}}"></template>
```
temp.wxml中:
```html
<template name="tmpl1">
<view>这是模板1:{{msg}}</view>
</template>
<template name="tmpl2">
<view>这是模板2:{{aaa}}</view>
</template>
```