微信小程序視圖template模板引用的實例詳解
更新時間:2017年09月20日 11:42:12 作者:今天一點(diǎn)也不冷
這篇文章主要介紹了微信小程序視圖template模板引用的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下
微信小程序視圖template模板引用的實例詳解
WXML 提供兩種文件引用方式import和include。
include可以將目標(biāo)文件除了的整個代碼引入,相當(dāng)于是拷貝到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> <!-- 標(biāo)題內(nèi)容 --> <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: "天不言自高,地不言自厚,奇跡,是不會在容易的道路上綻放的。人生沒有如果,只有后果和結(jié)果,過去的不再回來,回來的不再完美。", }, { date: "2022年 10月 9日 ", title: "夏天", header_url: "/images/3.png", image_url: "/images/8.jpg", content: "人生沒有如果,只有后果和結(jié)果,過去的不再回來,回來的不再完美。", }, ] //輸出出口 module.exports={ templates: content_for }
redirect.js引用
var content_data=require('../../template/template.js') // pages/redirect/redirect.js Page({ /** * 頁面的初始數(shù)據(jù) */ data: { }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ 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; }
本站關(guān)于小程序的文章還有很多,希望大家能搜索查閱,希望通過本文能幫助到大家,謝謝大家對本站的支持,
相關(guān)文章
基于HTML+JS實現(xiàn)網(wǎng)頁版蘋果計算器
這篇文章主要為大家詳細(xì)介紹了如何利用HTML+CSS+JS實現(xiàn)網(wǎng)頁版的蘋果計算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-06-06慕課網(wǎng)題目之js實現(xiàn)抽獎系統(tǒng)功能
這篇文章主要為大家詳細(xì)介紹了慕課網(wǎng)題目之js抽獎系統(tǒng)功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09JS實現(xiàn)為排序好的字符串找出重復(fù)行的方法
這篇文章主要介紹了JS實現(xiàn)為排序好的字符串找出重復(fù)行的方法,涉及JavaScript字符串運(yùn)算相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-03-03