最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

微信小程序的template模板如何使用

来源:动视网 责编:小采 时间:2020-11-27 20:08:03
文档

微信小程序的template模板如何使用

微信小程序的template模板如何使用:这次给大家带来的是微信小程序的template模板如何使用,微信小程序中提供了template使用,即相同的板块可以进行代码互用,如下方的效果图,就可以用template。这篇文章就给大家好好分析一下。模板定义模板最重要的是模板的名称,即""
推荐度:
导读微信小程序的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';

相信看了以上介绍你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

相关阅读:

vue.js的语法及常用指令的详解

怎么用JS做出按钮禁用和启用

vue.js 里如何做到父向子组件传参

文档

微信小程序的template模板如何使用

微信小程序的template模板如何使用:这次给大家带来的是微信小程序的template模板如何使用,微信小程序中提供了template使用,即相同的板块可以进行代码互用,如下方的效果图,就可以用template。这篇文章就给大家好好分析一下。模板定义模板最重要的是模板的名称,即""
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top