template模板的使用方法

模板


WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用。
定义模板

使用name属性,作为模板的名字。然后在<template/>内定义代码片段
使用模板

使用is属性,声明需要的使用的模板,然后将模板所需要的data传入

模板的作用域

模板拥有自己的作用域,只能使用data传入的数据。
example:
定义模板 
<template name="homecell">
     <view class="item">
            <image class="poster" src="{{item.images.small}}" />
            <view class="meta">
                <text class="title">{{item.title}}</text>
                <text class="sub-title">{{item.original_title}}({{item.year}})</text>
                <view class="artists">
                    <text wx:for="{{item.directors}}">{{item.name}}</text>
                </view>
            </view>
            <view class="rating">
                <text>{{item.rating.average}}</text>
            </view>
    </view>
 </template>
使用模板
<import src="../../commonXml/homecell.wxml" />  //引入模板
<loading hidden="{{!loading}}">加载中...</loading>
<scroll-view scroll-y="true" class="page-body">
    <navigator wx:for="{{movies}}" url="../movie/movie?id={{item.id}}">
       <template is="homecell" data="{{item}}"></template>  //声明需要的使用的模板使用data传入的数据。
    </navigator>
</scroll-view>

转载于:https://www.cnblogs.com/tian-sun/p/7405837.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值