微信小程序刷新,局部对象更新,不保留历史记录跳转

博客类小程序源码,快速开通流量主,代码地址

常用方法

  • 隐藏底部导航条 wx.hideTabBar()
  • 获取本地存储 wx.getStorageSync(‘userInfo’)
  • 设置标题 wx.setNavigationBarTitle({title:’’})

页面路由跳转

window.open,不保存历史记录

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'
})

猜你喜欢

转载自blog.csdn.net/orangpeng/article/details/114262359