小程序中template模块怎么用

发布时间:2021-01-26 12:42:49 作者:小新
来源:亿速云 阅读:140

这篇文章主要介绍小程序中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模块怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. 微信小程序模板template怎么用
  2. 微信小程序如何实现template模板

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

小程序

上一篇:小程序中如何使用wx:key提升wx:for的渲染效率

下一篇:如何使用xml

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》