>  기사  >  위챗 애플릿  >  WeChat 애플릿 템플릿 템플릿에 대한 자세한 설명

WeChat 애플릿 템플릿 템플릿에 대한 자세한 설명

小云云
小云云원래의
2018-05-15 10:16:343502검색

WeChat 미니 프로그램은 템플릿 사용을 제공합니다. 즉, 아래 렌더링과 같이 코드 상호 운용성을 위해 동일한 섹션을 사용할 수 있으며 템플릿을 사용할 수 있습니다. 이 글은 주로 WeChat 미니 프로그램 템플릿 사용에 대한 관련 정보를 소개합니다. 이 글이 모든 사람이 이러한 기능을 이해하고 숙달하는 데 도움이 되기를 바랍니다.

WeChat 미니 프로그램 템플릿 사용법

렌더링

1. 템플릿 정의

템플릿에서 가장 중요한 것은 템플릿의 이름인 ""입니다.

다음은 예제 템플릿 코드

<template name="postItem">
 <view class=&#39;post-container&#39;>
  <view class=&#39;post-author-date&#39;>
   <image class=&#39;post-author&#39; src=&#39;{{avatar}}&#39;></image>
   <text class=&#39;post-date&#39;>{{date}}</text>
  </view>
  <text class=&#39;post-title&#39;>{{title}}</text>
  <image class=&#39;post-image&#39; src=&#39;{{imgSrc}}&#39;></image>
  <text class=&#39;post-content&#39;>{{content}}</text>
  <view class=&#39;post-like&#39;>
   <image class=&#39;post-like-image&#39; src=&#39;/images/icon/chat.png&#39;></image>
   <text class=&#39;post-link-text&#39;>{{collection}}</text>
   <image class=&#39;post-like-image&#39; src=&#39;/images/icon/view.png&#39;></image>
   <text class=&#39;post-link-text&#39;>{{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;
}

2. 템플릿 활용

템플릿 파일 소개

is가 포함된 템플릿 파일을 사용하세요. 템플릿 정의를 사용하는 경우 루프의 이름 데이터는 ". ..", 그러면 항목의 모든 데이터를 평면화할 수 있으므로 템플릿에 "item.xx"를 작성할 필요가 없습니다. 항목에 속성을 직접 작성하면 됩니다. 템플릿 프로그램 wxml을 사용해야 합니다. file

<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 file

@import &#39;post-item/post-item-template.wxss&#39;;

관련 권장 사항 :

WeChat 애플릿이 검토를 통과하지 못한 경우 수행할 작업

WeChat 애플릿이 이미지 구성 요소 그림의 적응형 너비 비율을 구현하는 방법에 대한 예 공유

WeChat 애플릿이 팔로우 메뉴 효과와 루프 중첩 데이터 로딩을 구현하는 방법에 대한 자세한 설명

위 내용은 WeChat 애플릿 템플릿 템플릿에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.