template模板

一、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>

```

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值