微信小程序视图template模板引用的实例详解
网络编程 2021-07-04 17:32www.168986.cn编程入门
这篇文章主要介绍了微信小程序视图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.js Page({ / 页面的初始数据 / 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; }
本站关于小程序的文章还有很多,希望大家能搜索查阅,希望通过本文能帮助到大家,谢谢大家对本站的支持,
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指