小程序之頁面跳轉(zhuǎn)和參數(shù)傳遞

小程序官網(wǎng)關(guān)于Navigator介紹:

image.png

open-type = navigate
對應(yīng) wx.navigateTo的功能

open-type = redirect
對應(yīng) wx.redirectTo的功能

open-type = switchTab
對應(yīng) wx.switchTab的功能

open-type = reLaunch
對應(yīng) wx.reLaunch的功能
[1.1.0](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/compatibility.html)

navigateBack
對應(yīng) wx.navigateBack的功能


頁面跳轉(zhuǎn)時傳遞

主頁面:

<!-- sample.wxml -->
<view class="btn-area">
  <navigator url="/page/navigate/navigate?title=newPagePath" hover-class="navigator-hover">跳轉(zhuǎn)到新頁面</navigator>
  <navigator url="../../redirect/redirect/redirect?title=重定向頁面&ohterParmas=123" open-type="redirect" hover-class="other-navigator-hover">在當(dāng)前頁打開</navigator>
  <navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切換 Tab</navigator>
</view>
這里是帶參跳轉(zhuǎn)的,一個參數(shù)就用?=title,如果多個參數(shù)就是用?=title=”“&ohterParmas=”“。

頁面跳轉(zhuǎn)后,onload接受參數(shù)

Page({
  data:{
//不需要再寫user_id。
  },

    onLoad(options) {
      console.log('onLoad')
      console.log(options.user_id)
      if (options.user_id) {
        this.setData({
          user_id: options.user_id
        })
      } else {
        this.setData({
          user_id: '暫無'
        })
      }
    }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容