「小程序JAVA实战」小程序通用模板的使用(17)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-17/
小程序也为了页面增加了通用模板的功能,如何去理解一个通用的模板呢?模板的定义就是为了让我们的页面可以享受一些公用话的模板,模板可以我们当成js里面定义的通用方法,我们需要这些通用的模板的时候,只需要调用这些模板就可以了,并且模板也提供一些参数。源码:https://github.com/limingios/wxProgram.git 中的No.8
小程序的为页面定义通用模板
- template name =”[templateName]”
- 引用模板is = [templateName]
- 传入参数data = {{data}}
- 官方的阐述
>https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/template.html

- 演示 模板的概念
>WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用。
使用 name 属性,作为模板的名字。然后在template内定义代码片段,使用 is 属性,声明需要的使用的模板,然后将模板所需要的 data 传入,模板拥有自己的作用域,只能使用 data 传入的数据以及模版定义文件中定义的 模块。
templateIs.wxml
<!templateIs.wxml-->
<template name="mytemp">
<view>姓名:{{name}}</view>
<view>年龄:{{age}}</view>
<view>地址:{{address}}</view>
<view>备注:{{remark}}</view>
<view>msg:{{msg}}</view>
</template>
<view class="container">
<template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
<template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
<template is="mytemp" data="{{...person,msg,name:'limng',age:'永远18岁'}}" />
</view>
templateIs.js
//templateIs.js
//获取应用实例
const app = getApp()
Page({
data: {
person: {
address: "公众号:编程坑太多",
remark: "个人主页:www.idig8.com"
},
msg: "感谢关注,收藏!"
}
})

PS:应该是随着开发小程序项目的增多,肯定会积累一些代码,这些代码都可以通过抽离template的方式来方面后期的开发。
「小程序JAVA实战」小程序通用模板的使用(17)的更多相关文章
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
- 「小程序JAVA实战」小程序视频封面处理(48)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...
随机推荐
- Ubuntu 16.04安装QQ国际版
QQ国际版wine-qqintl的下载链接:http://pan.baidu.com/s/1jIwKdXs sudo apt install libgtk2.0-0:i386 sudo apt in ...
- ranch分析学习(二)
紧接上篇,今天我们来分析监督树的工作者,打工仔执行任务的人.废话不多少我们直接进入正题. 3.ranch_server.erl 整个文件的功能主要是存储tcp对应参数的的信息.信息的存储方式采用的 ...
- 使用SDWebImage加载大量图片后造成内存泄露的解决办法
SDWebImage的知名度就不用说了,github上近10k的star,国内外太多的App使用其进行图片加载. 但是最近在使用过程中发现,在UITableView中不断加载更多的内容,使用SDWeb ...
- LOJ2323. 「清华集训 2017」小 Y 和地铁 【搜索】【思维】【好】
LINK 思路 首先如果直接算每一个段有三个决策 左/右 上/下 跨不跨过端点 这样的复杂度是\((2^3)^{22}\),显然是无法接受的 然后考虑怎么优化这个东西 首先左右这个决策是没有意义的 因 ...
- Hive中日期处理
1.日期函数UNIX时间戳转日期函数:from_unixtime() 函数 格式 返回值 说明 from_unixtime from_unixtime(bigint unixtime[, string ...
- 揭示同步块索引(中):如何获得对象的HashCode
转自:http://www.cnblogs.com/yuyijq/archive/2009/08/13/1545617.html 题外话:为了尝鲜,也兴冲冲的安装了Win7,不过兴奋之余却郁闷不已,由 ...
- 51nod 1347 旋转字符串
S[0...n-1]是一个长度为n的字符串,定义旋转函数Left(S)=S[1…n-1]+S[0].比如S=”abcd”,Left(S)=”bcda”.一个串是对串当且仅当这个串长度为偶数,前半段和后 ...
- wpf 动态得到label的宽度(无刷新情况)
var l =newLabel(){Content="Hello"}; l.Measure(newSize(double.PositiveInfinity,double.Posit ...
- CMS搭建,织梦CMS使用教程
http://www.dedejs.com/ 织梦DedeCms 5.7全站去版权去广告方法(含后台) http://429006.com/article/technology/3367.htm 1. ...
- 自定义显示提示一段时间自动消失ShowMsgText控件
public partial class ShowMsgText : Label { public string TextMsg { get { return Text; } set { timer1 ...