微信小程序template模板使用
前言
微信小程序中提供了template使用,即相同的板块可以进行代码互用,如下方的效果图,就可以用template。
效果图
一、模板定义
模板最重要的是模板的名称,即""
以下是实例模板代码
<template name="postItem">
<view class='post-container'>
<view class='post-author-date'>
<image class='post-author' src='{{avatar}}'></image>
<text class='post-date'>{{date}}</text>
</view>
<text class='post-title'>{{title}}</text>
<image class='post-image' src='{{imgSrc}}'></image>
<text class='post-content'>{{content}}</text>
<view class='post-like'>
<image class='post-like-image' src='/images/icon/chat.png'></image>
<text class='post-link-text'>{{collection}}</text>
<image class='post-like-image' src='/images/icon/view.png'></image>
<text class='post-link-text'>{{reading}}</text>
</view>
</view>
</template>
wxss文件
.post-container {
display: flex;
flex-direction: column;
margin-top: 20rpx;
margin-bottom: 40rpx;
background-color: white;
border-bottom: 1px solid #ededed;
border-top: 1px solid #ededed;
padding-bottom: 5px;
}
.post-author-date {
margin: 10rpx 0 20rpx 10rpx;
}
.post-author {
width: 60rpx;
height: 60rpx;
vertical-align: middle;
}
.post-date {
margin-left: 20rpx;
vertical-align: middle;
margin-bottom: 5px;
font-size: 26rpx;
}
.post-title {
font-size: 34rpx;
font-weight: 600;
color: #333;
margin-bottom: 10px;
margin-left: 10px;
margin-right: 10px;
}
.post-image {
margin-left: 16px;
width: 100%;
height: 340rpx;
margin: auto 0;
margin-bottom: 15rpx;
}
.post-content {
color: #666;
font-size: 28rpx;
margin-bottom: 20rpx;
margin-left: 20rpx;
margin-right: 20rpx;
letter-spacing: 2rpx;
line-height: 40rpx;
}
.post-like {
font-size: 13px;
flex-direction: row;
line-height: 16px;
margin-left: 16px;
color: gray;
}
.post-like-image {
height: 16px;
width: 16px;
margin-right: 8px;
vertical-align: middle;
}
.post-link-text {
vertical-align: middle;
margin-right: 20px;
}
二、模板使用
引入模板文件
使用模板文件 用is 使用 模板定义时的名称 data里面是循环里面里面的数据 用“...”表示的话,就可以把item里面的数据全部平铺出来,这样在template里面就不用写“item.xx”了,直接写item里面的属性就可以了 要使用template的程序wxml文件
<import src="/UploadFiles/2021-04-02/post-item-template.wxml">wxss 文件
@import 'post-item/post-item-template.wxss';如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“微信小程序template模板实例详解”评论...
更新日志
2025年10月24日
2025年10月24日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
