微信小程序-UI控件的使用(2)
2017-01-11 13:14
351 查看
微信模版的使用:
新建一个templates目录,新建header.wxml,footer.wxml两个模版文件
header.wxml
footer.wxml
在app.wxss中写入样式:
模版的使用:
include和inport的区别:
include是将目标文件进行内容进行拷贝
inport是将目标文件进行导入,可以设置多个模版
点击事件和循环操作
index.js:
效果图如下:
新建一个templates目录,新建header.wxml,footer.wxml两个模版文件
header.wxml
<template name="header1"> <view class="header"> <text>这是头部模版-{{title}}</text> </view> </template>
footer.wxml
<template name="footer1"> <view class="footer"> <text>这是底部模版1-{{title}}</text> </view> </template> <template name="footer2"> <view class="footer"> <text>这是底部模版2-{{title}}</text> </view> </template>
在app.wxss中写入样式:
.header{ width: 100%; height: 44px; background-color: lightblue; text-align: center; } .header text{ line-height: 44px; } .footer{ width: 100%; height: 44px; background-color: lightblue; text-align: center; } .footer text{ line-height: 44px; } .content{ width: 100%; height: 400px; background-color: green; }
模版的使用:
<!--include 是把所有的头部导入--> <!--<include src="../templates/header"/>--> <import src="../templates/header"/> <template is="header1" data="{{title:'index header'}}" /> <view class="content"> <text>zw learn weixin</text> </view> <import src="../templates/footer"/> <!--指定特定的footer--> <template is="footer1" data="{{title:'index footer'}}"/>
include和inport的区别:
include是将目标文件进行内容进行拷贝
inport是将目标文件进行导入,可以设置多个模版
点击事件和循环操作
<view class="content"> <text>zw learn weixin</text> <button type="warn" size="{{default}}" bindtap="warnclick"> warn </button> <text wx:if="{{isShow}}">{{text}}</text> <view wx:for="{{news}}"> <text>{{index}}-{{item}}</text> </view> <view wx:for="{{news}}" wx:for-index="idx" wx:for-item="new"> <text>{{idx}}-{{new}}</text> </view> </view>
index.js:
Page({ data:{ text:"这是显示内容", isShow:false, news:['new1','new2','new3','new4'] }, onLoad:function(options){ // 生命周期函数--监听页面加载 }, onReady:function(){ // 生命周期函数--监听页面初次渲染完成 }, onShow:function(){ // 生命周期函数--监听页面显示 }, onHide:function(){ // 生命周期函数--监听页面隐藏 }, onUnload:function(){ // 生命周期函数--监听页面卸载 }, onPullDownRefresh: function() { // 页面相关事件处理函数--监听用户下拉动作 }, onReachBottom: function() { // 页面上拉触底事件的处理函数 }, onShareAppMessage: function() { // 用户点击右上角分享 return { title: 'title', // 分享标题 desc: 'desc', // 分享描述 path: 'path' // 分享路径 } }, warnclick:function(){ var show = this.data.isShow; var newtext = ''; this.setData({isShow:!show,text:'这是新内容'}); } })
效果图如下:
相关文章推荐
- 微信小程序-UI控件的使用(4)
- 微信小程序-UI控件的使用(1)
- 微信小程序-UI控件的使用(6)
- 微信小程序-UI控件的使用(5)
- 微信小程序-UI控件的使用(3)
- 【微信小程序】微信小程序中WeUI的使用
- 微信小程序video控件的使用
- 微信小程序中使用scroll-view控件实现上拉加载更多遇到的坑
- 浅谈微信小程序之官方UI框架we-ui使用教程
- 微信小程序之使用weui.wxss(八)
- 详细介绍微信小程序使用WEB-VIEW控件进行微信支付
- 微信小程序之官方UI框架we-ui 使用教程
- 1、微信小程序学习:基本控件的使用
- 使用ASP.NET AJAX Control Toolkit中的NoBot控件拒绝垃圾发布程序
- 在使用浏览器控件的程序中判断HTTP错误
- 使用ControlToolkit中的NoBot控件拒绝垃圾发布程序
- 在.net窗体程序中使用用户控件
- 使用ASP.NET AJAX Control Toolkit中的NoBot控件拒绝垃圾发布程序 【转载】
- 使用wmp控件连续播放多个声音文件的代码(计算机报时程序C#)
- TabCtrl控件的使用一则——程序架构