微信小程序——template的使用方法
今天需要做一个【我的订单】页面,订单有几种状态,觉得把订单列表封装成一个模板更好。下面讲一下,如何用小程序自带的template构建一个模板。
1.构建订单列表模板页,命名为 【order.wxml】。
文件目录:

order.wxml具体代码:
<template name="orderList">
<view class='order-item bg-white'>
<view class='order-list pdlr-15'>
<navigator url='../detail/index' class='row order-list-item fs-28'>
<image src='/images/avatar.png' mode='widthFix' class='order-img row-shrink'></image>
<view class='row-grow ml-10'>
<text class='course-name ellipsis-two fs-30'>{{name}}</text>
<text class='block fs-24 fc-99'>数量:{{count}}</text>
<text class='block fs-24 fc-99'>总价:{{price}}</text>
</view>
<view class='row-shrink text-right ml-10'>
<text class='block fc-blue fs-28'>{{status}}</text>
</view>
</navigator>
</view>
</view>
</template> <template name="data-null">
<view class='no-data'>
<image src="/images/no_data@2x.png" class='no-data-img'></image>
<text class='no-data-tips'>暂无数据</text>
</view>
</template>
记得要给template命名哦~调用的时候需要用到这个名字。
2.在pages/order/list/index.wxml里面调用这个模板,注意引用路径。

引用的代码:
<import src="/template/order/order.wxml" />
调用的代码:
<block wx:for="{{orderList}}" wx:for-item="order">
<template is="orderList" data="{{...order}}" />
</block>
index.js里面的orderList数据:

我们此时可以看到效果如下:

其他说明:
调用模板【页面index.wxml】的时候,我们看到 【data="{{...order}}"】这种写法,这是ES6的写法。
这样写的好处就是在【order.wxml】里面调用数据的时候不用写成【{{order.name}},{{order.count}}】这种形式,直接 【{{name}},{{count}}】就可以了。
微信小程序——template的使用方法的更多相关文章
- 微信小程序 template模板使用
参考文章: 微信小程序-template模板使用
- 微信小程序template模板与component组件的区别和使用
前言: 除了component,微信小程序中还有另一种组件化你的方式template模板,这两者之间的区别是,template主要是展示,方法则需要在调用的页面中定义.而component组件则有自己 ...
- 微信小程序页面跳转方法总结
微信小程序页面跳转目前有以下方法(不全面的欢迎补充): 1. 利用小程序提供的 API 跳转: // 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面.// 注 ...
- 微信小程序中使用Async-await方法异步请求变为同步请求
微信小程序中有些 Api 是异步的,无法直接进行同步处理.例如:wx.request.wx.showToast.wx.showLoading等.如果需要同步处理,可以使用如下方法: 注意: Async ...
- 微信小程序 template添加点击事件
介绍template是微信小程序提供的模板,可以在模板中定义代码片段,然后在不同的地方调用. 简单使用定义template因为项目中可能会需要到不止一个template,所以最好新建一个文件夹来存放t ...
- 微信小程序——template详细使用
WXML提供模板(template),可以在模板中定义代码片段,然后在不同的地方调用减少冗余代码. 1.1定义模板 1.1.1.创建模板文件夹 1.1.2.使用 name 属性,作为模板的名字.然后 ...
- WeChat-SmallProgram:微信小程序中使用Async-await方法异步请求变为同步请求
微信小程序中有些 Api 是异步的,无法直接进行同步处理.例如:wx.request.wx.showToast.wx.showLoading 等.如果需要同步处理,可以使用如下方法: 提示:Async ...
- 微信小程序template富文本插件image宽度被js强制设置
这段时间一直做微信小程序,过程中遇到了一个问题,这个问题一直没有得到完美的解决. 问题描述: 在Web编程中经常会引入template插件,这个插件是封装好,我们通常的做法是直接引入,配置简单,好用, ...
- 一种轻量级的微信小程序日志监控的方法
今天一个活动要写个H5,明天一个功能要用小程序,天天都在写bug.用户反馈小程序用起来有问题还特么还不知道到底出了啥bug,反馈多了,老板要扣工资了!看来挖了太多坑不填也不行,程序异常还是要主动追踪, ...
随机推荐
- unity, ios skin crash
https://issuetracker.unity3d.com/issues/ios-loading-models-with-tangents-set-to-calculate-legacy-fro ...
- [MeetCoder] Count Pairs
Count Pairs Description You are given n circles centered on Y-aixs. The ith circle’s center is at po ...
- FTP整站上传的批处理脚本
一个FTP整站上传的批处理代码.例子: @echo off rem 设置FTP服务器地址 set ftpIP=192.168.0.2 rem 设置FTP用户名 set ftpUser=MyUser r ...
- Atitit 项目界面h5化静态html化计划---vue.js 把ajax获取到的数据 绑定到表格控件 v2 r33.docx
Atitit 项目界面h5化静态html化计划---vue.js 把ajax获取到的数据 绑定到表格控件 v2 r33.docx 1. 场景:应用在项目列表查询场景下1 1.1. 预计初步掌握vue ...
- mongoose修改数组中某个特定的值
写博客的时候有一个这样的业务,一个标签集合和一个文章集合,它们是多对多的关系,文章集合中tags字段包含它对应的标签,现在修改标签集合中某条标签记录的名字,文章集合中所有包含这个标签的tags字段的值 ...
- FFmpeg(4)-使用avformat_find_stream_info()来探测获取封装格式的上下文信息
/** * Read packets of a media file to get stream information. This * is useful for file formats with ...
- jar依赖
https://blog.csdn.net/honghailiang888/article/details/53019635
- 每日英语:Google Scraps Plan to Build Hong Kong Data Center
Internet giant Google Inc. has scrapped a plan to build its own data center in Hong Kong and will in ...
- C# IOCP服务器项目(学习)
无论什么平台,编写支持高并发性的网络服务器,瓶颈往往出在I/O上,目前最高效的是采用Asynchronous I/O模型,Linux平台提供了epoll,Windows平台提供了I/O Complet ...
- Delphi下IOCP开源框架:DIOCP 成功应用案例分享
首先说明,该项目不是本人的项目,本文转自盒子. 该项目使用的DIOCP版本为1.0,目前diocp为3.5 以下是盒子的原文 ------------------------------------- ...