小编给大家分享一下微信小程序如何实现template模板,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!微信小程序template模板使用前言微信小程序中提供了template使用,即相同的
小编给大家分享一下微信小程序如何实现template模板,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
微信小程序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="post-item/post-item-template.wxml" />
<view>
<block wx:for="{{postList}}" wx:for-item="item">
<template is="postItem" data="{{...item}}" />
</block>
</view>
wxss 文件
@import 'post-item/post-item-template.wxss';
看完了这篇文章,相信你对“微信小程序如何实现template模板”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网VUE频道,感谢各位的阅读!
--结束END--
本文标题: 微信小程序如何实现template模板
本文链接: https://www.lsjlt.com/news/70704.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0