溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

小程序中template模塊怎么用

發(fā)布時間:2021-01-26 12:42:49 來源:億速云 閱讀:151 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹小程序中template模塊怎么用,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

WXML提供模板(template),可以在模板中定義代碼片段,然后在不同的地方調用。
首先在pages目錄下新建一個template目錄用來存放模板
模板怎么建呢?
模板只需要新建xxx.wxss和xxx.wxml這兩個文件就可以了,其他兩個.js和.json不需要
在template目錄中新建list-template.wxml和list-template.wxss

list-template.wxml:

<template name='listTmp'><view>
  <view>
    <image src='/images/avatar/0.png'></image>
    <text>may 9 2018</text>
  </view>
  <text>火影村</text>
  <image src='/images/detail/carousel/6.jpg'></image>
  <text>火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火火</text>
  <view>
    <image src='/images/icon/view.png'></image>
    <text>88</text>
    <image src='/images/icon/star.png'></image>
    <text>88</text>
  </view></view></template>

list-template.wxss:

.tmpContainer{
  display: flex;  
  flex-direction: column;
  }
.avatar_date image{
  width: 60rpx;  
  height: 60rpx;  
/* 把此元素放置在父元素的中部。就可以讓圖片與文字都在中間了 */
  vertical-align: middle;  
  margin-right: 10rpx;
  }
.avatar_date {
  padding: 10rpx;
  }
.avatar_date text{
  font-size: 32rpx;
  }
.company{
  margin-left: 10rpx;  
  font-size: 36rpx;  
  font-weight: 700;  
  margin: 10rpx;
  }
.contentImg{
  width: 100%;  
  height: 460rpx;
  }
.content{
  font-size: 32rpx;  
  /* 段落首字母縮進兩個字 */
  text-indent: 64rpx;
  }
.collection_love image{
  width: 32rpx;  
  height: 32rpx;  
  vertical-align: middle;  
  margin-right: 10rpx;
  }
.collection_love text{
  font-size: 28rpx;  
  margin-right: 10rpx;
  }

list.wxml中引入模板:

<!-- 在頭部引入,注意結尾別忘了/ -->
<import src='/pages/template/list-template.wxml'/>

然后在你想用模板的地方引用
小程序中template模塊怎么用還要在list.wxss中像以下樣子引入模板樣式

小程序中template模塊怎么用

以上是“小程序中template模塊怎么用”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI