初步学习微信小程序,开发过程中发现许多常用的代码块,特此记之,方便以后调用。
一、 tabar
"tabBar": {
"list": [
{
"iconPath": "images/index.png",
"selectedIconPath": "images/index.png",
"pagePath": "pages/index/index",
"text": "搜索"
},
{
"pagePath": "pages/dreams/dreams",
"text": "首页"
},
{
"pagePath": "pages/myDream/myDream",
"text": "我"
}
]
}
二、 页面跳转
方法一:
<navigator url="../index/index">跳转到新页面</navigator>
<navigator url="../index/index"open-type="redirect">在当前页打开</navigator>
<navigator url="../index/index"open-type="switchTab">切换到首页Tab</navigator>
方法二:
bindTp:function(){
//保留当前页面,跳转到应用内的某个页面
wx.navigateTo({
url:''
})
//关闭当前页面,跳转到应用内的某个页面
wx.redirectTo({
url: '',
})
//跳转到tabBar页面,并关闭其他所有的tabBar页面
wx.switchTab({
url: '',
})
//返回上一页面或多级页面
wx.navigateBack({
data:1
})
},
三、设置页面分享
onShareAppMessage: function () {
return {
title: '周公解梦',
path: '/pages/index/index',
success: function (res) {
console.log(res)
}
}
}
带参数页面分享
onShareAppMessage: function () {
return {
title: '周公解梦',
path: '/pages/index/index?id=3',
success: function (res) {
console.log(res)
}
}
}
获取传递过来的参数
onLoad: function (options) {
if (options.uid != undefined){
wx.showToast({
title: '来自用户:' + options.uid +"的分享",
icon:'success',
duration:2000
})
}
}
四、微信小程序之选项卡
在发现选项卡之前,要想实现这个功能我只能想到写多个xml文件实现转换,或者在wxml界面进行判断,今天又get到一个新技能!可参考以下网址:http://www.wxapp-union.com/article-2350-1.html
wxml文件:
<view class="swiper-tab">
<view class="swiper-tab-item {
{
currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">最新</view>
<view class="swiper-tab-item