常用方法
- 隐藏底部导航条 wx.hideTabBar()
- 获取本地存储 wx.getStorageSync(‘userInfo’)
- 设置标题 wx.setNavigationBarTitle({title:’’})
页面路由跳转
wx.redirectTo({
url: 'test?id=1'
})
wx.navigateTo({
url: 'test?id=1'
})
- 跳转到tabBar页面,并关闭其他所有非tabBar页面
wx.switchTab({
url: '/index'
})
wx.reLaunch({
url:'/pages/index/index'
});
生命周期函数
函数 | 说明 |
---|
onLoad | 初始化相关参数,路由接参 |
onReady | 监听页面初次渲染完成 |
onShow | 监听页面显示 |
onHide | 监听页面隐藏 |
onUnload | 监听页面卸载 |
onPullDownRefresh | 监听用户下拉动作 |
onReachBottom | 页面上拉触底 |
绑定事件,获取参数
<button bindtap="btnclick"></button>
<button catchtap="btnclick"></button>
<button catchtap="btnclick" data-item={{obj}}></button>
//获取obj
let obj = e.currentTarget.dataset.item
- tap:点击事件;
- longtap:长按事件;
- touchstart:触摸开始;
- touchend:触摸结束;
- touchcansce:取消触摸;
- catch绑定能阻止事件冒泡)
数据更新,重新渲染页面
//更新obj里面的某个参数
this.setData({
['snsData.setMenuListShow']:!snsData.setMenuListShow
});
//整个对象更新
this.setData({
obj:'123'
})
作者的小程序
![微雅视频](https://img-blog.csdnimg.cn/20201216154044274.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L29yYW5ncGVuZw==,size_16,color_FFFFFF,t_70#pic_center)