微信小程序开发常用方法
1、函数中访问data中的数据
_this.setData({
// 日历数据
signList: dataList,
// 当前日期
todayDay: str
})
2、if判断
wx:if="{{item.id && item.lessNum != 0}}"
3、for循环
>
4、小程序实现登录界面
html页面
<form bindsubmit="formSubmit">
<text class="login_title">登录</text>
<input class="ipt_login" name="userName" value="{{userName}}"/>
<input class="ipt_login" name="userPassword" type="password" value="{{userPassword}}"/>
<button class="btn_login" form-type="submit">登录</button>
</form>
js页面
//logs.js=
Page({
data: {
logs: [],
userName: '请输入登录名',
userPassword: ''
},
// 登录
formSubmit: function (e) {
console.log(e.detail.value);
//获得表单数据
var objData = e.detail.value; if (objData.userName && objData.userPassword) {
// 同步方式存储表单数据
wx.setStorage({
key: 'userName',
data: objData.userName
});
wx.setStorage({
key: 'userPassword',
data: objData.userPassword
}); //跳转到成功页面
wx.navigateTo({
url: '../lineOrder/index'
})
}
},
//加载完后,处理事件
// 如果有本地数据,则直接显示
onLoad: function (options) {
var that = this;
//获取本地数据
wx.getStorage({
key: 'userName',
success: function (res) {
console.log(res.data);
that.setData({ userName: res.data });
}
});
wx.getStorage({
key: 'userPassword',
success: function (res) {
console.log(res.data);
that.setData({ userPassword: res.data });
}
});
}
})
获取本地存储
var session_id = wx.getStorageSync('PHPSESSID');// 获取一步存储
小程序的本地存储是无时间限制的,就是说永远
5、自定义属性
<view class='showList ' bindtop='shopPost' data-shopId='item.goods_id' ></view> 页面中自定义属性必须通过:data- 的形式书写
js取值
shopPost:function(event){ var postId = event.currentTarget.dataset.shopid }
最后的 shopid 就是 html 中的 data后边的,并且在这里不区分大小写,必须用小写
小程序模仿jq的 toggleClass,多个选项,点击哪个哪个高亮显示,再次点击去掉高亮显示。
<block wx:for="{{listRepar}}" wx:key="unique" wx:for-index="i" wx:for-item="item">
<view class="tabBox {{item.checked != true ? ' ' : 'active'}}" bindtap="chooseItem" data-repId="{{item.repair_type_id}}">
<view class='nameWei'><image class='nameWeiPic' src="{{item.repair_photo}}"></image>{{item.repair_type}}</view>
<view class='nameWord'>{{item.repair_info}}</view>
</view>
</block>
js。高亮是用 class active 控制,点击的时候获取自定义属性 id,用这个 id 和原有的数据list对比找到那个id的数据,改变他的 checked 的属性。小程序没有 addclass这些方法,所以判断高亮的时候,给每一个数据item 都加一个 checked的属性,true 就代表高亮。
改变数据的 item 之后一定要在赋值回去,吧原先的数据改变掉。
chooseItem: function (e) {
var dId = e.currentTarget.dataset.repid,
listReparDta = this.data.listRepar,
_this = this;
for (var i = ; i < listReparDta.length; i++){
if (listReparDta[i].repair_type_id == dId){
listReparDta[i].checked = !listReparDta[i].checked;
}
_this.setData({
listRepar: listReparDta
});
}
},
6、页面的跳转
7、动态控制 class
<li class="{{item.date != '' ? ' ' : 'empty'}}" data-dateId='{{item.date}}' bindtap="chooseDay">
8、使用小程序拨打电话
<button type="default" bindtap="calling">拨打电话</button>
Page({
calling:function(){
wx.makePhoneCall({
phoneNumber: '', //此号码并非真实电话号码,仅用于测试
success:function(){
console.log("拨打电话成功!")
},
fail:function(){
console.log("拨打电话失败!")
}
})
}
})
9、小程序图片给定宽度,让高度自使用
样式设置宽度例如:100%,
.img{
width: %;
}
添加属性 mode="widthFix",
<image class="img" src="../../images/hello.png" mode="widthFix">
10、小程序底部按钮点击切换配置
底部的按钮点击切换在小程序里面是通过配置得来的。
在 app.json 文件中配置相关选项
{
"pages":[
"pages/index/index",
"pages/priceType/index",
"pages/logs/logs",
"pages/lineOrder/index",
"pages/chooseTap/index",
"pages/main/index"
],
"window":{
navigationBarBackgroundColor 导航栏背景颜色,如”#000000”
navigationBarTextStyle 导航栏标题颜色,仅支持 black/white
navigationBarTitleText 导航栏标题文字内容
backgroundColor 窗口的背景色
backgroundTextStyle 下拉背景字体、loading 图的样式,仅支持 dark/light
enablePullDownRefresh 是否开启下拉刷新,详见页面相关事件处理函数
},
"tabBar": {
"color": "#6e6d6b",
"selectedColor": "#f9f027",
"borderStyle": "white",
"backgroundColor": "#292929",
"list": [
{
"pagePath": "pages/index/index",
// "iconPath": "images/footer-icon-01.png",
// "selectedIconPath": "images/footer-icon-01-active.png",
"text": "首页"
},
{
"pagePath": "pages/main/index",
// "iconPath": "images/footer-icon-02.png",
// "selectedIconPath": "images/footer-icon-02-active.png",
"text": "我的"
}
]
},
"debug": true
}
10、小程序点击穿透事件
<!-- 综合筛选 -->
<view class='choose_dailog' wx:if='{{isShowDailog}}' bindtap='showDailog' catchtouchmove="stopMove">
<view class='dailog_wrap'>
<view>
<view class="dailogC_titile">性别</view>
<view class="overflowStyle">
<view
class="{{item.checked == true ? 'active': ' '}} choose_itemDailog"
wx:for="{{sexDate}}" wx:key="index"
catchtap="chooseSex" data-repId="{{item.id}}"
>
{{item.text}}
</view>
</view>
</view>
<view class="dailog_footer">
<view class="dailog_footer_item one">重置</view>
<view class="dailog_footer_item two">完成</view>
</view>
</view>
</view>
bind 换为 catch 则不会向上穿透
微信小程序开发常用方法的更多相关文章
- 微信小程序开发心得
微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...
- 【微信小程序开发•系列文章六】生命周期和路由
这篇文章理论的知识比较多一些,都是个人观点,描述有失妥当的地方希望读者指出. [微信小程序开发•系列文章一]入门 [微信小程序开发•系列文章二]视图层 [微信小程序开发•系列文章三]数据层 [微信小程 ...
- 微信小程序开发日记——高仿知乎日报(下)
本人对知乎日报是情有独钟,看我的博客和github就知道了,写了几个不同技术类型的知乎日报APP 要做微信小程序首先要对html,css,js有一定的基础,还有对微信小程序的API也要非常熟悉 我将该 ...
- 微信小程序开发日记——高仿知乎日报(中)
本人对知乎日报是情有独钟,看我的博客和github就知道了,写了几个不同技术类型的知乎日报APP要做微信小程序首先要对html,css,js有一定的基础,还有对微信小程序的API也要非常熟悉 我将该教 ...
- 微信小程序开发日记——高仿知乎日报(上)
本人对知乎日报是情有独钟,看我的博客和github就知道了,写了几个不同技术类型的知乎日报APP 要做微信小程序首先要对html,css,js有一定的基础,还有对微信小程序的API也要非常熟悉 我将该 ...
- 微信小程序开发工具测评
1月9日微信小程序正式上线.很多企业都希望能在这个.但是在技术开发的问题上,却不知道该如何下手.经过一些程序员不辞辛苦连夜测试,终于从十余款工具呕心沥血筛选出四款比较靠谱实用的微信小程序开发工具.接下 ...
- 微信小程序开发工具的数据,配置,日志等目录在哪儿? 怎么找?
原文地址:http://www.wxapp-union.com/portal.php?mod=view&aid=359 本文由本站halfyawn原创:感谢原创者:如有疑问,请在评论内回复 ...
- 微信小程序开发工具使用与设计规范(二)
[未经作者本人同意,请勿以任何形式转载] 上一篇文章主要分析了微信小程序应用场景和优劣势.本篇你可以学习到: 如何使用小程序开发工具写一个Hello World 微信小程序设计规范 微信小程序项目结构 ...
- 微信小程序开发视频教程新鲜出炉
微信小程序开发公测了,可是对于新手来说,不同的框架不同的开发机制,如何快速适应呢?微信小程序开发视频教程新鲜出炉了,从零开始一步一步搭建微信小程序,每个章节都会涉及到不同的知识点,等教程学习完你不但掌 ...
随机推荐
- POJ River Hopscotch 二分搜索
Every year the cows hold an event featuring a peculiar version of hopscotch that involves carefully ...
- Mac OSX:安装zsh
想在mac下安装oh my zsh,按照https://github.com/robbyrussell/oh-my-zsh上的文档,执行下面这条命令安装:curl -L http://install. ...
- 新的HTML5语义元素
先看一个传统的HTML4的文档: <div class="header"> <h1>My Site Name</h1> <h2>My ...
- iOS:解决pod的Insecure world writable dir问题
当我们运行pod setup的命令的时候,有时候会碰到这个警告: /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods/execut ...
- JEval使用实例
jeval是为为你的Java应用程序提供可增加的.高性能.数学. 布尔和函数表达式的解析和运算的高级资源包. 以下这个样例包括了JEval经常使用功能: package demo0; import ...
- php session自定义处理
原文:http://www.cnblogs.com/mrcoke/ 这个人的博客上转的. 这个博客也好: 学算法和数据结构!!http://blog.csdn.net/21aspnet/articl ...
- Java UDP通信简单实现
1.Java实现方式 1)server端 /** * UDPserver端 * */ public class UdpServer { // 定义一些常量 private final intMAX_L ...
- 【翻译自mos文章】在12c数据库中,哪种audit trail 受到支持?
在12c数据库中,哪种audit trail 受到支持? 来源于:What Audit Trail Types Are Supported For A 12c Database? (文档 ID 198 ...
- A*(也叫A star, A星)寻路算法Java版
寻路算法有非常多种,A*寻路算法被公觉得最好的寻路算法. 首先要理解什么是A*寻路算法,能够參考这三篇文章: http://www.gamedev.net/page/resources/_/techn ...
- 设计模式学习–Decorator
What Decorator:动态地给一个对象加入一些额外的职责. 就添加功能来说.Decorator模式相比生成子类更加灵活. Why Decorator模式适用于能够动态的给对象增删职责.比方qq ...