网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序template模板使用

發布時間:2018-01-02 09:20 所屬欄目:小程序開發教程

微信小程序中提供了template使用,即相同的板塊可以進行代碼互用,如下方的效果圖,就可以用template。

 
 
 

前言

微信小程序中提供了template使用,即相同的板塊可以進行代碼互用,如下方的效果圖,就可以用template。

效果圖

 

一、模板定義

模板最重要的是模板的名稱,即"" 
以下是實例模板代碼

 

						
  1. <template name="postItem">
  2. <view class='post-container'>
  3. <view class='post-author-date'>
  4. <image class='post-author' src='{{avatar}}'></image>
  5. <text class='post-date'>{{date}}</text>
  6. </view>
  7. <text class='post-title'>{{title}}</text>
  8. <image class='post-image' src='{{imgSrc}}'></image>
  9. <text class='post-content'>{{content}}</text>
  10. <view class='post-like'>
  11. <image class='post-like-image' src='/images/icon/chat.png'></image>
  12. <text class='post-link-text'>{{collection}}</text>
  13. <image class='post-like-image' src='/images/icon/view.png'></image>
  14. <text class='post-link-text'>{{reading}}</text>
  15. </view>
  16. </view>
  17. </template>

wxss文件

 

						
  1. .post-container {
  2. display: flex;
  3. flex-direction: column;
  4. margin-top: 20rpx;
  5. margin-bottom: 40rpx;
  6. background-color: white;
  7. border-bottom: 1px solid #ededed;
  8. border-top: 1px solid #ededed;
  9. padding-bottom: 5px;
  10. }
  11.  
  12. .post-author-date {
  13. margin: 10rpx 0 20rpx 10rpx;
  14. }
  15.  
  16. .post-author {
  17. width: 60rpx;
  18. height: 60rpx;
  19. vertical-align: middle;
  20. }
  21.  
  22. .post-date {
  23. margin-left: 20rpx;
  24. vertical-align: middle;
  25. margin-bottom: 5px;
  26. font-size: 26rpx;
  27. }
  28.  
  29. .post-title {
  30. font-size: 34rpx;
  31. font-weight: 600;
  32. color: #333;
  33. margin-bottom: 10px;
  34. margin-left: 10px;
  35. margin-right: 10px;
  36. }
  37.  
  38. .post-image {
  39. margin-left: 16px;
  40. width: 100%;
  41. height: 340rpx;
  42. margin: auto 0;
  43. margin-bottom: 15rpx;
  44. }
  45.  
  46. .post-content {
  47. color: #666;
  48. font-size: 28rpx;
  49. margin-bottom: 20rpx;
  50. margin-left: 20rpx;
  51. margin-right: 20rpx;
  52. letter-spacing: 2rpx;
  53. line-height: 40rpx;
  54. }
  55.  
  56. .post-like {
  57. font-size: 13px;
  58. flex-direction: row;
  59. line-height: 16px;
  60. margin-left: 16px;
  61. color: gray;
  62. }
  63.  
  64. .post-like-image {
  65. height: 16px;
  66. width: 16px;
  67. margin-right: 8px;
  68. vertical-align: middle;
  69. }
  70.  
  71. .post-link-text {
  72. vertical-align: middle;
  73. margin-right: 20px;
  74. }
 

二、模板使用

引入模板文件  使用模板文件 用is 使用 模板定義時的名稱  data里面是循環里面里面的數據 用“...”表示的話,就可以把item里面的數據全部平鋪出來,這樣在template里面就不用寫“item.xx”了,直接寫item里面的屬性就可以了  要使用template的程序wxml文件

 

						
  1. <import src="post-item/post-item-template.wxml" />
  2. <view>
  3. <block wx:for="{{postList}}" wx:for-item="item">
  4. <template is="postItem" data="{{...item}}" />
  5. </block>
  6. </view>

wxss 文件

 

						
  1. @import 'post-item/post-item-template.wxss';


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18349.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×