微信小程序template模板引用实例详解

广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买

微信小程序template模板引用实例详解

本文主要和大家介绍微信小程序视图template模板引用的实例详解的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下,希望能帮助到大家。

微信小程序视图template模板引用的实例详解

WXML 提供两种文件引用方式import和include。

include可以将目标文件除了的整个代码引入,相当于是拷贝到include位置

temlate.wxml

<template name="tmp_data" >   <view class="content">    <!-- 头像 -->    <view class="author-date">       <image src="{{item.header_url}}" class="author"></image>      <text class="date">{{item.date}}{{idx}}</text>    </view>    <!-- 标题内容 -->     <text class="title">{{item.title}}</text>     <image class="image" src="{{item.image_url}}"></image>     <text class="article-content">{{item.content}}</text>    <view >     <image class="article-images" src="../../images/icon/chat.png"></image>     <text class="article-text">66</text>     <image class="article-images" src="../../images/icon/view.png"></image>     <text class="article-text">88</text>    </view>  </view></template>
登录后复制

redirect.wxml引用

<import src="template/template.wxml" />
登录后复制

template.js

var content_for = [ {  date: "2020年 10月 9日 ",  title: "那年夏天",  header_url: "/images/3.png",  image_url: "/images/6.jpg",  content: "天不言自高,地不言自厚,奇迹,是不会在容易的道路上绽放的。人生没有如果,只有后果和结果,过去的不再回来,回来的不再完美。", }, {  date: "2022年 10月 9日 ",  title: "夏天",  header_url: "/images/3.png",  image_url: "/images/8.jpg",  content: "人生没有如果,只有后果和结果,过去的不再回来,回来的不再完美。", },]//输出出口module.exports={ templates: content_for}
登录后复制

redirect.js引用

var content_data=require('../../template/template.js')// pages/redirect/redirect.jsPage({ /**  * 页面的初始数据  */ data: { }, /**  * 生命周期函数--监听页面加载  */ onLoad: function (options) {   this.setData({     key: content_data.templates   }); }});
登录后复制

wxml

 <block wx:for="{{key}}" wx:for-item="item" wx:for-index="idx">     <!-- is就是模板名字name值 -->     <template is="tmp_data" data="{{item}}" />   </block>
登录后复制

template.wxss文件

.title{ font-size: 34rpx; font-weight: 600; color:#333; margin-bottom: 20px;}
登录后复制

redirect.wxss文件引用上面样式

@import "template/template.wxss" //使用import定义swiper{ width:100%; height:500rpx;}swiper image{  width:100%; height:500rpx;}
登录后复制

相关推荐:

微信小程序template模板详解

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

微信小程序之template模板介绍

以上就是微信小程序template模板引用实例详解的详细内容,更多请关注9543建站博客其它相关文章!

广告:SSL证书一年128.66元起,点击购买~~~

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。

作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:yii代表着什么
下一篇:已是最新文章

发表评论

关闭广告
关闭广告